From 02ef0d170e7755842d7c14d6cfb92fc6a42a8d05 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 28 Oct 2026 11:12:02 +0800 Subject: [PATCH 1/3] fix(ci): register issue4982 draining-twin-ladder process-spawning suite in LIVE_FILES (#4982) --- scripts/live-files.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/live-files.mjs b/scripts/live-files.mjs index e2a58f9f45..315ddf7172 100644 --- a/scripts/live-files.mjs +++ b/scripts/live-files.mjs @@ -68,6 +68,11 @@ export const LIVE_FILES = [ // servers; every socket is listen(0), spawns are mocked, so the zone band // is belt-and-braces like #3890's — the entry is for the tripwire "tests/issue4811-dsh-busy-drop-selfheal.test.ts", + // #4982: integration rows spawn bili children against freePort() picks and + // follow each child's REGISTERED port (ladder-tolerant); BASE is an + // in-memory-only value, so no zone band is needed — the entry is for the + // tripwire + "tests/issue4982-draining-twin-ladder.test.ts", ]; /** Band width per live file: the zone ladder drifts +1 per EADDRINUSE retry; From 499f69ef9652de439a341e2f464139fdd3ef4434 Mon Sep 17 00:00:00 2001 From: ci-check Date: Wed, 28 Oct 2026 12:37:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?test:=20follow-up=20#5016=20=E2=80=94=20mak?= =?UTF-8?q?e=20the=20#4982=20e2e=20pin=20actually=20pass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two latent defects in tests/issue4982-draining-twin-ladder.test.ts shipped with PR #5016, both on paths that only run once the fix under test works: 1. Self-contradictory assertion: the demotion warn added by the fix names "twin-collision" in its own text (src/server.ts), while test B asserts doesNotMatch(/twin-collision/) over the whole log — impossible to satisfy, so test B fails deterministically on every CI run. Pin the verdict by its unique log marker (shared by the early #4341 and late paths) instead of the substring; test A's parallel assertion gets the same marker. 2. Teardown deadlock: silentTcpListener accepted probe connections and held them; a socket with no data listener stays paused, so peer EOF is never delivered once the probing child dies, leaving CLOSE-WAIT sockets that pin squatter.close() forever (verified via ss during the hang) and the test ends by node:test cancellation. Drain each connection (sock.resume()) and destroy it on EOF. Test-only change; no production behavior touched. --- tests/issue4982-draining-twin-ladder.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/issue4982-draining-twin-ladder.test.ts b/tests/issue4982-draining-twin-ladder.test.ts index b1bc2db71b..8514862190 100644 --- a/tests/issue4982-draining-twin-ladder.test.ts +++ b/tests/issue4982-draining-twin-ladder.test.ts @@ -242,8 +242,13 @@ async function killChild(child: ChildProcess): Promise { * EADDRINUSE decision path instead of the pre-bind foreign-owner ladder. */ function silentTcpListener(port: number): Promise { return new Promise((resolve, reject) => { - const server = net.createServer(() => { - /* accept and hang — never answer HTTP */ + const server = net.createServer((sock) => { + // accept and hang — never answer HTTP; drain the probe's bytes so peer + // EOF is actually delivered (a paused socket buffers them and never sees + // EOF) and release the connection, or a dead prober pins server.close() + // with CLOSE-WAIT sockets + sock.resume(); + sock.on("end", () => sock.destroy()); }); server.once("error", reject); server.listen(port, "127.0.0.1", () => resolve(server)); @@ -374,7 +379,7 @@ test("#4982 e2e: draining same-lane predecessor + squatter → newcomer ladders const p2Marker = readMarkers(stateHome).find((m) => m.pid === p2.child.pid); assert.equal(p2Marker?.lane, "pi"); assert.equal(p2Marker?.port, result.servedPort); - assert.doesNotMatch(p2.out.value, /twin-collision/, "the stale claim must not produce a twin-collision verdict"); + assert.doesNotMatch(p2.out.value, /already served by a same-build bili instance/, "the stale claim must not produce a twin-collision verdict"); await killChild(p2.child); held.destroy(); @@ -430,7 +435,10 @@ test("#4982 e2e: unverified registry twin claim (unstamped marker) → ladder, n assert.notEqual(result.servedPort, port, "P2 must ladder off the contended port"); const logText = fs.readFileSync(path.join(stateHome, "billion-context", "bili.log"), "utf8"); assert.match(logText, /no longer answers as itself/, "the demotion from twin to foreign-held must be logged"); - assert.doesNotMatch(logText, /twin-collision/, "an unverified claim must never reach the twin-collision verdict"); + // The demotion warn above deliberately names "twin-collision" in prose, so pin + // the verdict by its unique log marker (shared by the early #4341 and the late + // path) instead of that substring. + assert.doesNotMatch(logText, /already served by a same-build bili instance/, "an unverified claim must never reach the twin-collision verdict"); await killChild(p2.child); await new Promise((resolve) => squatter.close(() => resolve())); From c24c30341aa11a4e9fb5845e644accd4818fa357 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Wed, 28 Oct 2026 18:12:49 +0800 Subject: [PATCH 3/3] test(#4982): self-cleaning finally + bounded status probes so a future failure reports instead of hanging (#5017) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up on 499f69ef (keeps its assertion markers and squatter listener): - e2e A/B cleanup moves into finally — with cleanup after the assertions, an assertion failure leaked the P1/P2 children + squatter server and hung the whole runner instead of reporting the failure reason. - waitForStatus fetch gets AbortSignal.timeout(2_000) — undici's default ~300s headers timeout would otherwise defeat the declared poll deadlines. Verified both directions locally (Node v25.9.0): green path 6/6 in ~21s with clean exit; a forced assertion failure now fails fast (~10s) with the real AssertionError and leaves no sandbox/child behind. --- tests/issue4982-draining-twin-ladder.test.ts | 32 ++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/issue4982-draining-twin-ladder.test.ts b/tests/issue4982-draining-twin-ladder.test.ts index 8514862190..71ea29a279 100644 --- a/tests/issue4982-draining-twin-ladder.test.ts +++ b/tests/issue4982-draining-twin-ladder.test.ts @@ -216,7 +216,7 @@ async function waitForStatus(port: number, timeoutMs: number): Promise const deadline = Date.now() + timeoutMs; for (;;) { try { - const res = await fetch(`http://127.0.0.1:${port}/__bili/status`); + const res = await fetch(`http://127.0.0.1:${port}/__bili/status`, { signal: AbortSignal.timeout(2_000) }); if (res.status === 200) return true; } catch { // connection refused while the child is still starting up — expected @@ -332,9 +332,14 @@ test("#4982 e2e: draining same-lane predecessor + squatter → newcomer ladders const { stateHome } = sandboxDirs(sandbox); const port = await freePort(); await assertPortDead(port, { label: "4982 drain-test port" }); + let p1Ref: ReturnType | null = null; + let p2Ref: ReturnType | null = null; + let heldRef: net.Socket | null = null; + let squatterRef: net.Server | null = null; try { // P1: the serving proxy that will enter graceful shutdown. const p1 = spawnBili(sandbox, port); + p1Ref = p1; if (!(await waitForStatus(port, 90_000))) throw new Error(`P1 never became ready:\n${p1.out.value}`); const p1Marker = readMarkers(stateHome).find((m) => m.pid === p1.child.pid); assert.ok(p1Marker, "P1 must have registered itself"); @@ -346,6 +351,7 @@ test("#4982 e2e: draining same-lane predecessor + squatter → newcomer ladders s.once("connect", () => resolve(s)); s.once("error", reject); }); + heldRef = held; p1.child.kill("SIGTERM"); const p1MarkerFile = path.join(stateHome, "billion-context", "instances", `${p1Marker.instanceId}.json`); @@ -362,9 +368,11 @@ test("#4982 e2e: draining same-lane predecessor + squatter → newcomer ladders // The squatter takes the freed port BEFORE the newcomer starts — but // silently, so the newcomer's pre-bind claim probe sees no evidence. const squatter = await silentTcpListener(port); + squatterRef = squatter; // P2: same lane, same requested port — the CI victim. const p2 = spawnBili(sandbox, port); + p2Ref = p2; const result = await Promise.race([ new Promise<"exited">((resolve) => p2.child.once("exit", () => resolve("exited"))), (async () => { @@ -380,12 +388,14 @@ test("#4982 e2e: draining same-lane predecessor + squatter → newcomer ladders assert.equal(p2Marker?.lane, "pi"); assert.equal(p2Marker?.port, result.servedPort); assert.doesNotMatch(p2.out.value, /already served by a same-build bili instance/, "the stale claim must not produce a twin-collision verdict"); - - await killChild(p2.child); - held.destroy(); - await killChild(p1.child); - await new Promise((resolve) => squatter.close(() => resolve())); } finally { + // Cleanup lives in finally so an assertion failure reports its reason + // instead of leaking the children + squatter and hanging the runner. + if (p2Ref) await killChild(p2Ref.child); + heldRef?.destroy(); + if (p1Ref) await killChild(p1Ref.child); + const squatter = squatterRef; + if (squatter) await new Promise((resolve) => squatter.close(() => resolve())); fs.rmSync(sandbox, { recursive: true, force: true }); } }); @@ -395,6 +405,8 @@ test("#4982 e2e: unverified registry twin claim (unstamped marker) → ladder, n const { stateHome } = sandboxDirs(sandbox); const port = await freePort(); await assertPortDead(port, { label: "4982 unverified-twin port" }); + let p2Ref: ReturnType | null = null; + let squatterRef: net.Server | null = null; try { // A registry marker claiming `port` with a LIVE pid and full identity // match — but NO portReleasedAt stamp (pre-fix build, or a failed @@ -420,8 +432,10 @@ test("#4982 e2e: unverified registry twin claim (unstamped marker) → ladder, n }) + "\n", ); const squatter = await silentTcpListener(port); + squatterRef = squatter; const p2 = spawnBili(sandbox, port); + p2Ref = p2; const result = await Promise.race([ new Promise<"exited">((resolve) => p2.child.once("exit", () => resolve("exited"))), (async () => { @@ -439,10 +453,10 @@ test("#4982 e2e: unverified registry twin claim (unstamped marker) → ladder, n // the verdict by its unique log marker (shared by the early #4341 and the late // path) instead of that substring. assert.doesNotMatch(logText, /already served by a same-build bili instance/, "an unverified claim must never reach the twin-collision verdict"); - - await killChild(p2.child); - await new Promise((resolve) => squatter.close(() => resolve())); } finally { + if (p2Ref) await killChild(p2Ref.child); + const squatter = squatterRef; + if (squatter) await new Promise((resolve) => squatter.close(() => resolve())); fs.rmSync(sandbox, { recursive: true, force: true }); } });