Skip to content

Commit ff0113f

Browse files
authored
bugfix: clear wait timer in ngx_http_lua_pipe_proc_wait_cleanup to prevent SIGSEGV on QUIC connection close
1 parent f4c76d8 commit ff0113f

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/ngx_http_lua_pipe.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,11 @@ ngx_http_lua_pipe_proc_wait_cleanup(void *data)
26162616
wait_co_ctx->cleanup = NULL;
26172617

26182618
if (proc->pipe == NULL) {
2619+
/* pipe_proc_destroy already ran (LIFO pool cleanup) and closed
2620+
* connections, but wait uses wait_co_ctx->sleep (a standalone event,
2621+
* not tied to any connection), so ngx_close_connection in
2622+
* pipe_proc_destroy cannot cancel it. Clear it here. */
2623+
ngx_http_lua_pipe_clear_event(&wait_co_ctx->sleep);
26192624
return;
26202625
}
26212626

t/191-pipe-proc-quic-close-crash.t

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,31 @@ GET /t
9999
--- curl_error eval: qr/\(28\)/
100100
--- no_error_log
101101
[alert]
102+
103+
104+
105+
=== TEST 2: pipe wait timer must not fire after pool is freed on QUIC connection close
106+
--- config
107+
location = /t {
108+
content_by_lua_block {
109+
local proc = require("ngx.pipe").spawn({"sleep", "100"})
110+
-- set_timeouts(write_timeout, stdout_timeout, stderr_timeout, wait_timeout)
111+
proc:set_timeouts(nil, nil, nil, 1000) -- 1 s wait timeout
112+
113+
-- This call yields and arms a 1 s timer on wait_co_ctx->sleep.
114+
-- Unlike stdout/stderr read timers (tied to a connection),
115+
-- the wait timer is a standalone ngx_event_t, so
116+
-- ngx_close_connection in pipe_proc_destroy cannot cancel it.
117+
-- Without the fix in wait_cleanup, the timer fires after pool
118+
-- is freed → SIGSEGV in ngx_http_lua_pipe_resume_wait_handler.
119+
proc:wait()
120+
}
121+
}
122+
--- request
123+
GET /t
124+
--- timeout: 0.5
125+
--- wait: 2
126+
--- ignore_response
127+
--- curl_error eval: qr/\(28\)/
128+
--- no_error_log
129+
[alert]

0 commit comments

Comments
 (0)