From 93ec6980a75155b820370dabfb45268558786aac Mon Sep 17 00:00:00 2001 From: awork Date: Fri, 16 Oct 2026 22:07:15 +0800 Subject: [PATCH 1/2] test: make issue1452 stall-guard waits load-robust (deadline poll, not fixed sleep) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discovered while reviewing PR #3409: its windows-latest(22,1) shard failed on 'retired stall guard: mid-stream silence survives any short window' (first chunk should have flowed through) — a fixed 2s wall-clock sleep that starves under runner load. Convert both fixed-sleep waits in this file that gate assertions on async events to the file's own deadline-poll idiom; the mid-stream test keeps its 2s observation floor so the negative assertions still cover a window far past the retired 400ms guard. --- tests/issue1452-socket-hardening.test.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/issue1452-socket-hardening.test.ts b/tests/issue1452-socket-hardening.test.ts index 1958f7a62c..637111107c 100644 --- a/tests/issue1452-socket-hardening.test.ts +++ b/tests/issue1452-socket-hardening.test.ts @@ -314,8 +314,14 @@ test("exposure telemetry: periodic info line with liveConns breakdown (#1452)", let harness: Harness | null = null; try { harness = await startProxy(upstream, false); - await new Promise((r) => setTimeout(r, 400)); - const line = captured.find((c) => /\[exposure\] uptime=/.test(c.msg)); + // Deadline poll instead of a fixed sleep: under CI load a fixed window can + // elapse before the first interval tick lands (#3409 CI flake class). + const deadline = Date.now() + 5000; + let line = captured.find((c) => /\[exposure\] uptime=/.test(c.msg)); + while (!line && Date.now() < deadline) { + await new Promise((r) => setTimeout(r, 10)); + line = captured.find((c) => /\[exposure\] uptime=/.test(c.msg)); + } assert.ok(line, `expected [exposure] telemetry line, got: ${captured.map((c) => c.msg).join(" | ")}`); assert.match(line!.msg, /liveConns=\d+ tcpHandles=\d+ handles=\d+ sessions=\d+ blindTunnels=\d+ inFlight=\d+/); assert.equal(line!.level, "info"); @@ -400,7 +406,15 @@ test("retired stall guard: mid-stream silence survives any short window even wit }, ); req.end(STREAM_BODY); - await new Promise((r) => setTimeout(r, 2000)); + // Poll for the first chunk with a deadline instead of a fixed 2s sleep: + // under CI load a fixed window can elapse before the chunk arrives + // (#3409 CI flake on windows-latest). The 2s floor below stays so the + // negative assertions still cover a window far past the retired 400ms guard. + const t0 = Date.now(); + while (Date.now() - t0 < 15_000 && seen.join("").length === 0) { + await new Promise((r) => setTimeout(r, 10)); + } + await new Promise((r) => setTimeout(r, Math.max(0, 2000 - (Date.now() - t0)))); const soFar = seen.join(""); assert.ok(soFar.length > 0, "first chunk should have flowed through"); assert.ok(!soFar.includes("stream error"), `retired guard must not emit a truncation error: ${soFar.slice(0, 300)}`); From 07424ad66961569d731508319e684de28f3a79d4 Mon Sep 17 00:00:00 2001 From: awork Date: Sat, 17 Oct 2026 02:35:02 +0800 Subject: [PATCH 2/2] test: bound the stall-guard first-byte wait by event-loop ticks, not wall clock (#3435 addendum) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deadline-poll variant still budgets the wait in Date.now() time. Client, proxy and upstream share ONE process, so a single runner freeze (observed ~42s on windows-latest in run 38930761011, issue #3435) freezes the round trip AND the deadline together: the first post-unfreeze poll iteration sees the budget expired and asserts before the poll phase can deliver the chunk. Tick counting measures process-relative progress — the same frame the retired 400ms guard lives in — so arbitrarily long freezes survive; healthy runners exit after a few ticks; a dead stream stays bounded by the tick cap plus the in-process idle-budget cut. --- tests/issue1452-socket-hardening.test.ts | 26 +++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/issue1452-socket-hardening.test.ts b/tests/issue1452-socket-hardening.test.ts index 637111107c..2a5effe69e 100644 --- a/tests/issue1452-socket-hardening.test.ts +++ b/tests/issue1452-socket-hardening.test.ts @@ -406,15 +406,27 @@ test("retired stall guard: mid-stream silence survives any short window even wit }, ); req.end(STREAM_BODY); - // Poll for the first chunk with a deadline instead of a fixed 2s sleep: - // under CI load a fixed window can elapse before the chunk arrives - // (#3409 CI flake on windows-latest). The 2s floor below stays so the - // negative assertions still cover a window far past the retired 400ms guard. - const t0 = Date.now(); - while (Date.now() - t0 < 15_000 && seen.join("").length === 0) { + // Wait for the first chunk by EVENT-LOOP TICKS, not wall clock: client, + // proxy and upstream share this process, so a runner stall freezes the + // round trip AND any Date.now() deadline together — the ~42s + // windows-latest freeze in run 38930761011 (#3435) would blow past a + // wall-clock budget before the chunk lands. Ticks measure process- + // relative progress (the frame the retired 400ms guard itself lives in): + // a few ticks on healthy runners; a dead stream is bounded by the tick + // cap and by BILI_UPSTREAM_TIMEOUT_MS cutting it with an in-band frame. + let tick = 0; + while (seen.join("").length === 0 && tick < 500) { await new Promise((r) => setTimeout(r, 10)); + tick++; + } + // Observation floor in the same tick frame (~2s nominal): keep watching + // until ≥200 ticks have elapsed since the request, so the negative + // assertions still cover a window far past the retired 400ms guard's + // old cut point (#3409 fix intent). + while (tick < 200) { + await new Promise((r) => setTimeout(r, 10)); + tick++; } - await new Promise((r) => setTimeout(r, Math.max(0, 2000 - (Date.now() - t0)))); const soFar = seen.join(""); assert.ok(soFar.length > 0, "first chunk should have flowed through"); assert.ok(!soFar.includes("stream error"), `retired guard must not emit a truncation error: ${soFar.slice(0, 300)}`);