Repository navigation
test(gateway): clear dangling intervals in close, runtime-services, and startup-post-attach tests - #98893
test(gateway): clear dangling intervals in close, runtime-services, and startup-post-attach tests#98893wangmiao0668000666 wants to merge 3 commits into
Conversation
…nd startup-post-attach tests
|
Codex review: needs maintainer review before merge. Reviewed July 2, 2026, 9:42 PM ET / 01:42 UTC. Summary PR surface: Tests +103. Total +103 across 3 files. Reproducibility: yes. from source: current main creates long-lived interval handles in the three named gateway test files, and test-level cleanup did not track them. I did not run tests because this review was constrained to read-only inspection. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Next step before merge
Security Review detailsBest possible solution: Keep the change scoped to test-owned interval tracking and merge after normal maintainer review; no production code or config changes are needed. Do we have a high-confidence way to reproduce the issue? Yes from source: current main creates long-lived interval handles in the three named gateway test files, and test-level cleanup did not track them. I did not run tests because this review was constrained to read-only inspection. Is this the best way to solve the issue? Yes: test-local handle tracking with afterEach cleanup is the narrowest maintainable fix because production close and maintenance paths already clear real runtime handles. A production-code change would be the wrong layer for this test leak. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against dae86e6bec01. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Tests +103. Total +103 across 3 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review Added a focused regression test in |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Added per-file active-handle proof and a process-level snapshot:
Zero PR body |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Closing to free active PR queue slots for P2 bug fixes. This test cleanup can be reopened or folded into a later cleanup pass once the queue is below the barnacle limit. |
What Problem This Solves
Three gateway test files create
setIntervalhandles as mock dependencies but never clean them up:src/gateway/server-close.test.ts:createGatewayCloseTestDeps()creates 3 intervals (tickInterval,healthInterval,dedupeCleanup) and is called from ~40 test cases. The existingafterEachresets timer mode and env vars, but does not clear the intervals.src/gateway/server-runtime-services.test.ts:createMaintenanceHandles()creates 4 intervals. Some tests verify the production cleanup path clears them, but if a test fails before that path runs the intervals leak.src/gateway/server-startup-post-attach.test.ts: one test inline-creates 3setInterval(() => {}, 1 << 30)handles with no cleanup.Dangling intervals keep worker event loops alive, increase
/tmp/process pressure, and can cause flakiness when tests run with--isolate=false.Why This Change Was Made
Adds a consistent
trackTestIntervalhelper in each file that records everysetIntervalhandle created by test helpers, and clears them inafterEach. This mirrors the existingtest/helpers/temp-dir.tspattern for temp-directory lifecycle management, applied to timer handles.Changes per file:
server-close.test.ts: module-leveltestIntervalHandles+trackTestInterval; clear all tracked intervals in the existingafterEach.server-runtime-services.test.ts: same pattern;createMaintenanceHandles()now tracks all 4 returned intervals.server-startup-post-attach.test.ts: describe-level tracker; the inlinetickInterval/healthInterval/dedupeCleanupare tracked and cleared inafterEach.No production code is changed.
User Impact
Test-only. Reduces dangling interval leaks during gateway test runs. No user-visible behavior change.
Evidence
Unit tests:
Results:
Lint:
→ exit 0
Typecheck:
→ exit 0
Real behavior proof
The regression test added to each of the three files uses
process.getActiveResourcesInfo()(a Node.js-builtin API that returns one entry per live resource handle, includingTimeoutfor each live interval) to print active-handle counts before, during, and after a tracked-interval block.Behavior addressed: gateway tests no longer leak
setIntervalhandles between cases;afterEachclears all entries in each file'stestIntervalHandlesarray.Real environment tested: Linux x86_64 (kernel 4.19.112-2.el8), Node v22.22.0, vitest shard
test/vitest/vitest.gateway.config.ts.Exact steps or command run after this patch:
Evidence after fix (per-file, captured on commit
3787962e14):Each
beforereading is the Vitest-suite-internal baseline (a single Timeout).duringjumps by exactly the number of intervals the helper creates in that file (3, 4, 3 respectively), andafterreturns to the baseline. The[interval-cleanup]line is emitted byconsole.loginside the test, captured by--reporter=verbose.Per-file interval counts:
during - beforeserver-close.test.tscreateGatewayCloseTestDepstickInterval,healthInterval,dedupeCleanup)server-runtime-services.test.tscreateMaintenanceHandlestickInterval,healthInterval,dedupeCleanup,mediaCleanup)server-startup-post-attach.test.tssetInterval(() => {}, 1 << 30)× 3In every case
after === before, which only happens when all tracked intervals are cleared.Negative control (process-level snapshot, no mocking):
process.getActiveResourcesInfo()was sampled in the parent Node process (not Vitest) immediately before and after a full gateway-shard run that includes the three target files:Result:
The parent process holds zero
Timeouthandles before and after the full gateway-shard run;diff=0confirms no interval handles escape the test files.Observed result after fix: per-test cleanup paths remove all tracked intervals (
after === beforein every file); the parent process holds zero extraTimeouthandles after the full shard run.What was not tested: full CI suite (triggered on push to remote).
process.getActiveResourcesInfo()is a per-isolate snapshot of the live event-loop state; countingTimeouthandles covers every interval type this PR introduces (none of them usesetImmediateorsetTimeout).AI-assisted
Implemented and verified with AI assistance; reviewed by a human before submission.