fix(devframe): stop mcp-http tests from sharing a port#86
Merged
Conversation
Every test in mcp-http.test.ts booted its dev server on the same default port (9999). Since Node's global fetch() (undici) pools keep-alive sockets per origin, a later test could get handed a stale socket left over from an earlier test's already-closed server — failing instantly with a socket error, or leaving the earlier server's close() hanging until undici's keep-alive timeout released it. This was flaking CI's unit-test job on every platform/Node version. Pass port: 0 so each boot() gets a fresh OS-assigned port, eliminating the origin collision entirely. 🤖 Generated with an agent (opencode).
✅ Deploy Preview for devfra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
mcp-http.test.tswas flaking CI's unit-test job on every platform/Node version, always failing on afetch failed/SocketError: other side closed.Root cause
Every test in the file booted its dev server via
createDevServerwithout an explicit port, so eachboot()bound to the same default port (9999). Since all five tests run in the same Node process, Node's globalfetch()(undici) pools keep-alive sockets per origin (http://127.0.0.1:9999) — it has no idea the server behind that origin was torn down and replaced by a fresh instance between tests.Two failure shapes fell out of this:
fetch()could get handed a stale, already-dead socket left over from an earlier (now-closed) test's server, failing near-instantly with a socket error.close()would hang for ~4 seconds (undici's default client-sidekeepAliveTimeout) waiting for the client to release an idle pooled socket before the underlying connection could actually end.Confirmed locally: the specific test failed ~50% of repeated runs before the fix, and 0/50 after.
Fix
Pass
port: 0to eachcreateDevServercall in the test file so the OS assigns a fresh ephemeral port per test, eliminating the origin collision entirely. Test-only change — no production code touched.Verification
mcp-http.test.tsrun 50 times in a loop: 0 failures (was ~50% failure rate before).pnpm build && pnpm test: 63/63 test files, 642/642 tests pass.pnpm lint: clean.pnpm typecheck: clean.🤖 This PR was created with the help of an agent (opencode).