Skip to content

fix(test): widen pollWithTimeout window in mcp lifecycle abort assertions - #208

Merged
alltomatos merged 1 commit into
devfrom
claude/fix-mcp-lifecycle-poll-timeout-207
Sep 12, 2026
Merged

alltomatos merged 1 commit into
devfrom
claude/fix-mcp-lifecycle-poll-timeout-207

Conversation

@alltomatos

Copy link
Copy Markdown
Owner

Issue for this PR

Closes #207

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

bun run test (the regular unit suite, not test:httpapi) intermittently fails test/mcp/lifecycle.test.ts's "add() closes the old protocol session when replacing a server" with error: replaced HTTP session was not aborted.

Root cause: three scenarios in this file poll for a session/transport abort signal via pollWithTimeout(), whose default window is 5 seconds (test/lib/effect.ts). Under CI-load variance that window is tight enough for legitimate (if slow) abort/teardown latency to miss it — the same class of issue already documented and fixed for subprocess timeouts in #191/#202 ("widen with headroom rather than shave to the exact miss").

Widened the timeout to 10 seconds for all three affected scenarios:

  • "disconnect removes protocol data and reconnect establishes a new session" (disconnected HTTP session abort)
  • "add() closes the old protocol session when replacing a server" (replaced HTTP session abort) — the one observed failing in CI
  • "remote timeout aborts both real HTTP transport attempts" (remote transport abort)

Confirmed this is a legitimate-latency issue, not a genuine app-level hang: the abort does complete, just not always inside the old 5s window under load.

How did you verify your code works?

  • bun test test/mcp/lifecycle.test.ts --timeout 60000 → 21/21 pass, run 3x consecutively with 0 flakes.
  • bun turbo typecheck → all 30 packages pass.

Screenshots / recordings

N/A (test-only change, no UI impact).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

…ions

Closes #207

Three scenarios in test/mcp/lifecycle.test.ts poll for a session/transport
abort signal via pollWithTimeout(), whose default window is 5 seconds
(test/lib/effect.ts). Under CI-load variance that window is tight enough
for legitimate (if slow) abort/teardown latency to miss it — the same
class of issue already documented and fixed for subprocess timeouts in
#191/#202 ("widen with headroom rather than shave to the exact miss").

Widened to 10 seconds for:
- "disconnect removes protocol data and reconnect establishes a new
  session" (disconnected HTTP session abort)
- "add() closes the old protocol session when replacing a server"
  (replaced HTTP session abort) — the one observed failing in CI
- "remote timeout aborts both real HTTP transport attempts" (remote
  transport abort)

Verified: `bun test test/mcp/lifecycle.test.ts --timeout 60000` passes
21/21, run 3x consecutively with 0 flakes. `bun turbo typecheck` passes.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@alltomatos
alltomatos merged commit c2ecb85 into dev Sep 12, 2026
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky: mcp/lifecycle.test.ts 'add() closes the old protocol session when replacing a server' times out under load

1 participant