Skip to content

Commit af76f2c

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

2 files changed

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

0 commit comments

Comments
 (0)