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

Open
#4,693 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@jkugsiya is already working on this.

Since Oct 7, 2026.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
nodejs, typescript, vite

Research direction

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.

Written by the indexing model from the issue text.

Description

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
Dominant language
TypeScript
Stars
11.5k
Forks
968
Avg merge
4d 9h
Merged PRs (30d)
64

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.