openresty / openresty/lua-nginx-module
ngx.pipe do not close the pipe when the child process exit
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
If the user does not call ngx.pipe.wait or ngx.pipe.wait returns timeout, ngx_http_lua_pipe_t will be freed by ngx_http_lua_ffi_pipe_proc_destroy which is called when the request exit or when the ngx.pipe is collected by gc.
There are three connections in the ngx_http_lua_pipe_t which connect to the stdin/stdout/stderr of the child process.
If the request lasts for a long time, the connections will not be freed until the request is freed.
The privileged process has only 512 connections by default. The privileged process may run out of the connections when there are lots of ngx.pipe that is not collected by the gc.
location / {
content_by_lua_block {
local ngx_pipe = require "ngx.pipe"
local proc, err = ngx_pipe.spawn({"sh", "-c", "sleep 1; echo 100; sleep 5;"})
if not proc then
ngx.say(err)
return
end
proc:set_timeouts(nil, nil, nil, 2000)
local data, err, partial = proc:stdout_read_line()
ngx.say(data)
}
}
we can check the free connections by the following cmd
gdb --batch -q -p pid_of_process -ex "print ngx_cycle->free_connection_n" 2>/dev/null
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ngx_http_lua_pipe_t through ngx_http_lua_ffi_pipe_proc_destroy, ngx.pipe.wait, and the ngx.pipe.spawn/read flow described in the reproduction. Recreate the long-lived request and inspect free connections with the provided GDB command; done means the stdin, stdout, and stderr connections are released when the child exits, including when wait times out.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, lua, nginx
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100