Skip to content

Commit 7eb8ad0

Browse files
bugfix: ngx.pipe waits until timeout because child process forgot to close pipe after dup2.
After the fork, the pipe will be copied by dup2, so there are two fd for the same open file description. eg: 0, 11 for the same pipe file, 1, 13 for another pipe file. When running a short life process, the fd will be closed automatically when the process exits. When running a daemon process, the daemon may close fd 0, fd 1 and redirect them to /dev/null, but left the fd 11 and fd 13 opened forever. when ngx.pipe reads from the pipe, it will wait for reading until the pipe is closed or timeout. Because the daemon won't close the pipe, so ngx.pipe will wait for the timeout.
1 parent 30debf6 commit 7eb8ad0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ngx_http_lua_pipe.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,12 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc,
773773
}
774774
}
775775

776+
close(in[0]);
777+
close(out[1]);
778+
if (!merge_stderr) {
779+
close(err[1]);
780+
}
781+
776782
if (environ != NULL) {
777783
#if (NGX_HTTP_LUA_HAVE_EXECVPE)
778784
if (execvpe(file, (char * const *) argv, (char * const *) environ)

0 commit comments

Comments
 (0)