Repository navigation
Conversation
Merge upstream master 6a641f3, including the architecture module-map and schedule-independent ranxianglei#2929 probe fixes. Preserve the existing PR head and exact contribution patch. Validation of this refreshed head runs in upstream CI; no local test rerun is claimed.
|
Review 结论:方向对,但 修复本身没问题:install/remove 幂等 + close 时摘除,解决了内嵌 server 反复起停重复挂处理器的问题。但摘除时机有个洞:
修法: 已验证:新回归测试在未修代码上红、修后绿(第二次 Ctrl+C 窗口内处理器必须在位);相邻 server 生命周期测试(server-close-all-connections / issue4982 / issue5167)13/13 通过;typecheck 通过。 我对该分支没有 push 权限,请应用以下补丁(或给我写权限,我来推): From 6b7865d847e7da14817b6bc5e563c9fd1f630fde Mon Sep 17 00:00:00 2001
From: ranxianglei <ranxianglei@users.noreply.github.com>
Date: Wed, 18 Nov 2026 09:18:58 +0800
Subject: [PATCH] fix: keep signal handlers alive during the shutdown flush
window
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
close fires when the listener stops accepting, i.e. before the session
flush in finishDrain. Removing the handlers there left a second Ctrl+C
during the flush window unhandled — the process died with unflushed
compression state. Skip removal while shuttingDown; a closed embedded
server that never shut down (port-ladder retry) still cleans up.
(cherry-pick pending: proposed fix for PR #7026)
---
src/server.ts | 7 +++++
tests/server-process-listeners.test.ts | 38 ++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/src/server.ts b/src/server.ts
index 9bdf2dc91..3e7ecb5f4 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -1832,6 +1832,13 @@ export async function startServer(opts: ProxyOptions): Promise<http.Server> {
}
const removeProcessHandlers = (): void => {
if (!processHandlersInstalled) return;
+ // #7026 review: the close event fires when the listener stops accepting,
+ // i.e. BEFORE the session flush in finishDrain. Stripping the handlers
+ // here would leave a second Ctrl+C during the flush window unhandled —
+ // the process would die with unflushed compression state. Keep them
+ // until the process actually exits; a closed embedded server that never
+ // shut down (port-ladder retry path) still cleans up normally.
+ if (shuttingDown) return;
processHandlersInstalled = false;
process.removeListener("uncaughtException", onUncaughtException);
process.removeListener("unhandledRejection", onUnhandledRejection);
diff --git a/tests/server-process-listeners.test.ts b/tests/server-process-listeners.test.ts
index cad3f910e..a736ffd7e 100644
--- a/tests/server-process-listeners.test.ts
+++ b/tests/server-process-listeners.test.ts
@@ -104,3 +104,41 @@ test("re-listening restores exactly one handler set and closing removes it again
restoreListeners(before);
}
});
+
+// #7026 review: the "close" event fires when the listener stops accepting, BEFORE
+// the session flush in finishDrain. Handlers stripped there left the flush window
+// unprotected — a second Ctrl+C would kill the process mid-flush. The handlers
+// must survive until the process actually exits. (Placed last: shutdown() latches
+// the module-level flag, so the clean-remove tests above must run first.)
+// #7026 review: the "close" event fires when the listener stops accepting,
+// BEFORE the session flush in finishDrain. Handlers stripped there left the
+// flush window unprotected — a second Ctrl+C would kill the process mid-flush.
+// The handlers must survive until the process actually exits. (Placed last:
+// shutdown() latches the module-level flag, so the clean-remove tests above
+// must run first.)
+test("graceful shutdown keeps signal handlers until the process exits", async () => {
+ const before = snapshot();
+ const realExit = process.exit;
+ const exits: Array<number | string | undefined> = [];
+ process.exit = ((code?: number | string) => { exits.push(code); }) as typeof process.exit;
+ const server = await start();
+ try {
+ const serving = snapshot();
+ process.kill(process.pid, "SIGINT");
+ await once(server, "close");
+ // Let the shutdown chain reach (the stubbed) process.exit first: the
+ // test process must not drain out from under the assertions while the
+ // flush is still running.
+ await new Promise((resolve) => setTimeout(resolve, 500));
+ assertSameListeners(serving);
+ // Second Ctrl+C during the flush window: must be absorbed by the
+ // idempotent shutdown(), not delivered to Node's default handler.
+ process.kill(process.pid, "SIGTERM");
+ await new Promise((resolve) => setImmediate(resolve));
+ assertSameListeners(serving);
+ assert.ok(exits.length <= 1);
+ } finally {
+ restoreListeners(before);
+ process.exit = realExit;
+ }
+});
--
2.43.0
|
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复 —— 本条是 PR #7026 的 review 跟进(guard 补丁),无其他同机制修复条目;PR 描述已声明与 #1240(logger EPIPE)、#4380(socket-linger)不同。 标签:bug / scope/wiring / p1(缺陷类;进程信号接线属 wiring;review 发现的 flush 窗口二次信号丢状态属数据丢失类,按 2026-10-19 口径 p1 不降 p2;无具体客户端,不打客户端标) 已独立复核诊断并应用补丁,但推 fork 分支被拒,需要你或 Afloat16 走一步(见下)。 诊断复核(代码路径已逐行核对)
分支上已做(commit
验证(独立重跑)
卡点:fork 无 push 权限
解法二选一
八问
判定:代码侧已收口(master 同步 + guard,红→绿、31/31、typecheck+build 全绿),分支处于可合并状态;唯一剩余动作是 fork push 权限(A/B 二选一),解阻后我立即推 PR 分支。 |
close fires when the listener stops accepting, i.e. before the session flush in finishDrain. Removing the handlers there left a second Ctrl+C during the flush window unhandled — the process died with unflushed compression state. Skip removal while shuttingDown; a closed embedded server that never shut down (port-ladder retry) still cleans up. (cherry-pick pending: proposed fix for PR ranxianglei#7026) (cherry picked from commit 6b7865d847e7da14817b6bc5e563c9fd1f630fde)
…led its own child on win32) test 4 (added by 894835a, #7026 review) assumed POSIX signal semantics: process.kill(self, SIGINT) was expected to dispatch to the installed handler and drive the graceful-shutdown chain. On WINDOWS the same call terminates the process (TerminateProcess) WITHOUT running the handlers - Node docs: 'On Windows, the signal being used to terminate a process cannot be changed. SIGTERM is sent.' Verified on a win10 box: SIGINT and SIGTERM self-kills die the process with the handler never invoked. The windows-latest CI child therefore died at the first kill line: file-level failure, zero TAP output, deterministic. Invoke the installed handler directly on win32 instead (the identical shutdown() path a console Ctrl+C would deliver). Also: bounded wait for the stubbed exit instead of a fixed 500ms sleep (each flush stage is deadline-capped at 5s, so a fixed sleep races slow volumes on every platform), and keep the exit stub in finally while the chain is still pending (last test in the file; a late REAL exit(0) would kill the runner before the TAP summary). Verified: 4/4 pass on a real win10 box (node v22.23.2), 4/4 on Linux.
Problem
Each
startServer()attaches process-level SIGINT/SIGTERM, uncaught-exception and rejection handlers. Closing the returned HTTP server leaves those closures registered. Repeated embedded start/close cycles therefore retain closed server instances, multiply logging, and leave their process-exiting shutdown callbacks subscribed to future signals.Change
Give this server's handlers stable identities and remove only those handlers on
close. Restore exactly one set when that same server listens again, including the port-claim retry path. Preserve foreign process listeners and handlers belonging to another live server. Keep the existing per-listen callback reset unchanged.Standalone proxy lifecycle only: plugin injection uses
createEngineContextand never installs these process handlers. Request payloads, compression modes, shutdown drain timing, and error classifications are unchanged.Verification
301e1a5459a77d5578206927c8062a58381af642.uncaughtExceptionlisteners.npm run typecheck,npm run build, andgit diff --check: passed.listeningcallbacks changed the existing linger test's behavior. That approach was removed; the final patch keeps the original reset and reinstalls only its own lifecycle hook. The unchanged close/linger suite passes on both the base and final patch.127.0.0.1:8199is unreachable. The real-model suite was not run, and its gate is unchanged.This is separate from #1240's logger EPIPE handling and #4380's socket-linger force-close behavior. Author history and live all-state searches for
startServer/process-listener cleanup found no equivalent fix.Fixes #7025