Repository navigation
test(website): reserve the dev-SSR port and hold it on both loopbacks - #1647
Merged
Merged
Conversation
The dev-SSR hydration e2e picked its port with getFreePort(), which closed the probe socket before the .vite cache removal and the vite spawn. On PR #1625 another process took the port in that window and the strictPort dev server died with "Port 41193 is already in use". - reserveFreePort() now holds the port on 127.0.0.1 and ::1. The servers listen on `localhost`, which Node can resolve to ::1, and a hold on 127.0.0.1 alone does not stop a ::1 listener from taking the same port. - The dev server clears the optimize-deps cache first, then reserves, and releases immediately before the spawn via startServerOnFreePort(). - startServerOnFreePort() retries, on a fresh reservation and at most three times, only when the child exits before listening because vite reported that exact port in use. The pnpm and vite startup between release and bind is a window no reservation can cover. - getFreePort() is removed; it had no other caller. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
trueadm
marked this pull request as ready for review
October 3, 2026 08:32
Contributor
Benchmark report🟢 No size increases and no timing regressions outside noise. Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)No changes across 45 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
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.
Summary
Test-harness only. This fixes the dev-SSR server's port race in
website/tests/ssr-hydration.e2e.test.ts. The website integration suite failed on #1625 (run 37106507164, job 111156042312) withserver for http://localhost:41193/ exited with code 1 before listening/Error: Port 41193 is already in use. The other 67 website tests passed.getFreePort(), which closed its probe socket before the.vitecache removal and the vite spawn. The cache is now removed first. The port is then reserved and released immediately beforespawnServer.reserveFreePort()holds the port on both127.0.0.1and::1. Vite (8.1.5,--strictPort) bindslocalhost, and Node resolves that to a single address, which can be::1. A hold on127.0.0.1alone said nothing about[::1]:port. Locallylocalhostresolves to::1first, and with only the IPv4 hold a second::1listener bound the same port. Holding both makes that bind fail withEADDRINUSE. A host without IPv6 loopback keeps the IPv4-only hold. This also covers the production preview reservation, which uses the same helper.release()has to come before the child binds, andpnpm exec vitethen loads its config and every plugin before it callslisten(). That window is much longer than the milliseconds betweenrelease()and the spawn, and no reservation can cover it.startServerOnFreePort()retries on a fresh reservation, at most three times. It retries only when the child exited before listening and vite reported that exact port as in use. Any other startup failure is rethrown unchanged.getFreePort()is removed. It had no other caller.The hardened properties from the earlier port-squatter fix are unchanged:
detached: truewith a process-group kill instopServer();waitForServerrejecting when the child exits.The spawn callback assigns
serveras it spawns, soafterAllstill stops the child if the hook times out mid-start.Validation
pnpm format:check, not run repo-wide.pnpm format:files:checkpasses on the four touched and related files.pnpm typecheck, not run repo-wide.pnpm typecheck:files website/tests/ssr-hydration.e2e.test.ts website/tests/support/server-process.ts website/tests/setup/production-server.ts website/tests/server-process.test.tspasses.pnpm test, not run locally because the machine is shared with parallel sessions. CI covers it.127.0.0.1held,::1binds the same port (the gap). With both held, it getsEADDRINUSE.localhostresolves to::1here.website/tests/server-process.test.ts(run by thewebsiteproject in CI; not run locally):127.0.0.1, and on::1when the host has it, untilrelease(). The::1case fails against the old IPv4-only reservation.Risk / follow-ups
project.providebefore the build, so its port cannot change. Closing that would mean moving the origin into the ready-state file. That is left out of this PR.Port <released port> is already in usemessage. A real startup failure still fails the suite on the first attempt.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Changes are limited to website test utilities and e2e setup; no production application or runtime behavior is modified.
Overview
Test-harness only: hardens website integration/e2e server startup so Vite dev SSR no longer flakes on
Port N is already in useunder--strictPort.reserveFreePort()now holds an ephemeral port on both127.0.0.1and::1(with retry when IPv6 side is taken), becauselocalhostmay bind only on::1while an IPv4-only hold left the same port free there.getFreePort()is removed.New
startServerOnFreePort()reserves, releases immediately before spawn, waits for listen, and retries up to three times only when the child exits before listening with Vite’s exact “that port already in use” message—covering the gap between release and Vite’s slowlisten().ssr-hydration.e2e.test.tsclears the.vitecache before reserving, then boots the dev server through this helper (assigningserverin the spawn callback for safe teardown).server-process.test.tsadds unit coverage for dual-loopback holds, successful retry on lost port, bounded retry, and no retry on other failures.Reviewed by Cursor Bugbot for commit 8df929d. Bugbot is set up for automated code reviews on this repo. Configure here.