Repository navigation
fix(vite): a dev page request whose ssr worker socket was reset is sent again instead of answering 500 - #571
Merged
Merged
Conversation
…nt again instead of answering 500 In dev, Nitro renders in a worker thread and the Vite middleware proxies each page request to it over a pooled keep-alive socket. A GET written to a socket the worker has just closed failed with `read ECONNRESET`, and Vite answered the navigation with its error-overlay page (500) instead of the app. A GET or HEAD whose socket was reset (ECONNRESET, EPIPE) is now re-sent once on a fresh socket. Other methods, other errors and a second reset still reach Vite's error page.
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.
In
adaptv dev web, Nitro renders pages in a worker thread and the Vite middleware proxies each page request to it with httpxy'sproxyFetch, over sockets pooled in a keep-alive agent. A request written to a pooled socket the worker had just closed failed withread ECONNRESET; Vite loggedInternal server error: read ECONNRESETand answered the navigation with its error-overlay page (500), not the app.It surfaced in the nightly
stress, chromiumcell:GET /answered 500 in 14 ms, about 6 s after the previous navigation, and the hydration gate reported "this document is not the app (no [data-adaptv-screen])". The page snapshot held only the overlay textread ECONNRESET at TCP.onStreamRead.This change re-sends a GET or HEAD once when the socket to the SSR worker is reset (
ECONNRESET,EPIPE). HTTP lets a client repeat an idempotent request whose connection closed before the response arrived (RFC 9112 §9.3.1). Other methods (a server function could run twice), other errors and a second reset still reach Vite's error page. The wrap sits onserver.environments.nitro.devServer.fetch, in dev only. A test pins the nitro call it relies on, so a nitro bump that moves the call fails the suite.Reproduce:
e2e-full (stress, chromium): the server log at 12:17:24 and the trace's network log (GET / 500 14ms).src/vite/dev-ssr-socket-reset.test.tsforces it: a server resets the second request on a reused socket, and httpxy's ownproxyFetchrejects withread ECONNRESET.Verify:
pnpm exec vitest run src/vite/dev-ssr-socket-reset.test.ts src/vite/deploy-server.test.ts: 16 passed. With the re-send disabled, "re-sends it once on a fresh socket" fails withError: read ECONNRESET.pnpm typecheck: clean.pnpm exec biome checkon the changed files: clean.pnpm test:e2e:stress --project=chromium e2e/stress-tasks.spec.ts --repeat-each=20: 120 passed (13.2 min), noECONNRESETin the server log.Tested on: Linux (WSL2), Node 22.23.3, chromium.
Not tested: webkit; the full stress project with --repeat-each (about 30 min per pass).