Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker process suffers CPU 100% usage #167

Open
tokers opened this issue Jun 30, 2019 · 3 comments
Open

worker process suffers CPU 100% usage #167

tokers opened this issue Jun 30, 2019 · 3 comments

Comments

@tokers
Copy link

tokers commented Jun 30, 2019

Hello!

The worker process CPU usage could be 100% if we use the following configuration pattern:

stream {
    server {
        listen 3105 reuseport;

        lua_check_client_abort on; # must be enabled

        content_by_lua_block {
            local sock, err = ngx.req.socket(true)

            sock:settimeout(1800 * 1000)

            local readline = sock:receiveuntil("\n")

            while not ngx.worker.exiting() do
                local line, err = readline(1)
                ngx.log(ngx.ERR, "line: ", line)
                if not line then
                    if err then
                        ngx.log(ngx.ERR, err)
                        break
                    end
                else
                    ngx.sleep(5000) -- other yieldable API is also applicable.
                end
            end
        }
    }
 }

Building a connection through nc and sending some characters then closing it, in the meanwhile, observing the CPU usage by top.

$ nc 127.0.0.1 3105
asjdkl
zxckj
^C

Now you can find the CPU usage reaches 100%.

It's irrelevant with the version of ngx_stream_lua, you can reproduce this problem even with the newest OpenResty.

After investigating the internal of stream-lua-nginx-module, I found it was caused by the indefinitely trigger of ngx_stram_lua_check_broken_connection, which doesn't the check ev->pending_eof flag.

BTW, this issue was found by @tianchaijz.

@tokers
Copy link
Author

tokers commented Jun 30, 2019

I have written a patch to solve this problem, I will push it to the meta-lua-nginx-module repo.

@tokers
Copy link
Author

tokers commented Jun 30, 2019

I have written a patch to solve this problem, I will push it to the meta-lua-nginx-module repo.

Nonetheless, I don't know why the ngx_stram_lua_check_broken_connection would be triggerd duplicately under the epoll ET mode.

@tokers
Copy link
Author

tokers commented Jun 30, 2019

@dndx Any idea about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant