Skip to content

fix(vite): a dev page request whose ssr worker socket was reset is sent again instead of answering 500 - #571

Merged
arrzdev merged 1 commit into
mainfrom
fix/dev-ssr-keepalive-reset
Nov 17, 2026
Merged

arrzdev merged 1 commit into
mainfrom
fix/dev-ssr-keepalive-reset

Conversation

@arrzdev

@arrzdev arrzdev commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

In adaptv dev web, Nitro renders pages in a worker thread and the Vite middleware proxies each page request to it with httpxy's proxyFetch, over sockets pooled in a keep-alive agent. A request written to a pooled socket the worker had just closed failed with read ECONNRESET; Vite logged Internal server error: read ECONNRESET and answered the navigation with its error-overlay page (500), not the app.

It surfaced in the nightly stress, chromium cell: 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 text read 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 on server.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:

  • CI: nightly run 43710798835, job e2e-full (stress, chromium): the server log at 12:17:24 and the trace's network log (GET / 500 14ms).
  • Locally the window is narrow. On an idle machine the agent drops its idle socket before the worker does: 0 resets in 167 page requests spaced 3.95 to 6.05 s apart. src/vite/dev-ssr-socket-reset.test.ts forces it: a server resets the second request on a reused socket, and httpxy's own proxyFetch rejects with read 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 with Error: read ECONNRESET.
  • pnpm typecheck: clean. pnpm exec biome check on the changed files: clean.
  • pnpm test:e2e:stress --project=chromium e2e/stress-tasks.spec.ts --repeat-each=20: 120 passed (13.2 min), no ECONNRESET in 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).

…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.
@arrzdev
arrzdev marked this pull request as ready for review November 17, 2026 01:03
@arrzdev
arrzdev merged commit f5e2fcf into main Nov 17, 2026
7 of 8 checks passed
@arrzdev
arrzdev deleted the fix/dev-ssr-keepalive-reset branch November 17, 2026 01:22
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.

1 participant