Vite dev proxy can reuse an expired worker socket after an event-loop stall (ECONNRESET)

Aperta
#4,693 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@jkugsiya ci sta già lavorando.

Dal 7/10/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript, vite

Direzione di ricerca

Start by running the linked reproduction with pnpm repro, then trace Nitro's development fetch through env-runner's BaseEnvRunner.fetch to httpxy's proxyFetch. Compare the failing run with control:idle and control:fresh, and use the shown shared-agent call as the boundary to investigate. Done means the blocked-parent scenario no longer fails while the existing controls and mutation-safety concern remain respected.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

dev vite
Environment
  • Nitro: 3.0.260903-beta (registry latest checked on 2026-10-01)
  • Vite: 8.3.1
  • env-runner: 0.2.3
  • httpxy: 0.5.5
  • srvx: 1.0.5
  • Node.js: 26.8.1
  • pnpm: 12.4.2
  • OS: Linux x86_64
  • Integration: nitro/vite, default Node worker runner

The reproduction is a standalone Nitro 3 + Vite project with one route returning new Response('ok'). It does not use Nuxt, TanStack Start, a database, or application lifecycle hooks.

Reproduction

https://github.com/grantsiemens/nitro-dev-proxy-repro

git clone https://github.com/grantsiemens/nitro-dev-proxy-repro.git
cd nitro-dev-proxy-repro
pnpm install --frozen-lockfile
pnpm repro

The project follows the suggested starter's one-route structure, adapted to Nitro 3's Vite plugin because the linked starter branch currently uses Nitro 2.

Please run it under native Node; the reported results were not verified in StackBlitz/WebContainers or CodeSandbox.

The script:

  1. Starts Vite with the real Nitro plugin and captures its Nitro instance through the module API.
  2. Calls nitro.fetch and consumes the successful response body.
  3. Pauses only the parent thread for 6.5 seconds using Atomics.wait. The stock worker keeps running and its unchanged HTTP server expires the idle connection.
  4. Calls nitro.fetch again immediately after the pause.

The second request fails with ECONNRESET. Read-only HTTP diagnostics record reusedSocket: true on the failed request. The script exits with code 1 after closing Vite and Nitro.

Controls included in the same project:

pnpm control:idle
pnpm control:fresh
  • control:idle replaces the blocking pause with an asynchronous delay of the same duration. Both requests succeed; exit code 0.
  • control:fresh retains the blocking pause and passes { agent: false } from env-runner to httpxy. Both requests succeed; exit code 0. This optional control applies the one-line change in memory; it does not modify installed files.

The default failing reproduction uses unmodified upstream packages. It does not destroy sockets, shorten server timeouts, replace the worker implementation, or restart workers between requests. The repository includes the lockfile and captured output for all three scenarios.

Describe the bug

Nitro's Vite development transport can reuse a pooled HTTP connection whose worker-side socket has expired while the parent event loop was blocked. The next otherwise valid request rejects with ECONNRESET rather than reaching the route.

The call path is Nitro's development fetch → env-runner BaseEnvRunner.fetch → httpxy proxyFetch, which uses a shared keep-alive agent by default.

This appears to be the general reused-socket race documented by Node:

https://nodejs.org/api/http.html#requestreusedsocket

Could this be handled or mitigated at the development transport boundary, or is there a supported configuration for avoiding worker-connection reuse? I am happy for this report to be transferred to env-runner/httpxy if that is the better owner.

Additional context

We investigated this after intermittent ECONNRESET failures in a larger application's development server. The isolated reproduction demonstrates the same transport failure without that application's code, but it does not establish that the original incidents involved this exact event-loop stall. Ordinary requests and asynchronous idle periods succeeded in the isolated checks.

Our current development-only workaround changes:

return proxyFetch(this._address, this._resolveFetchInput(input), init);

to:

return proxyFetch(this._address, this._resolveFetchInput(input), init, { agent: false });

This avoids connection reuse at the cost of a fresh local connection per request. It does not retry requests or suppress upstream errors. I am reporting it as a verified workaround, not assuming it is the preferred upstream fix; blindly retrying requests would be inappropriate for mutations.

Logs
Unmodified upstream transport (`pnpm repro`, exit 1):


Node v26.8.1; freshConnections=false; asyncIdle=false
First request: 200 ok
Pausing parent for 6500 ms; worker retains default idle timeout
{"code":"ECONNRESET","reusedSocket":true}
Request failed: ECONNRESET: socket hang up


Fresh-connection control (`pnpm control:fresh`, exit 0):


Node v26.8.1; freshConnections=true; asyncIdle=false
First request: 200 ok
Pausing parent for 6500 ms; worker retains default idle timeout
Second request: 200 ok


Asynchronous-idle control (`pnpm control:idle`, exit 0):


Node v26.8.1; freshConnections=false; asyncIdle=true
First request: 200 ok
Pausing parent for 6500 ms; worker retains default idle timeout
Second request: 200 ok
Lingua principale
TypeScript
Stelle
11.5k
Fork
968
Merge medio
4g 9h
PR unite (30g)
64

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nitrojs/nitro

Tutte le issue di nitrojs/nitro

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.