Skip to content

Dev server crashes with Unhandled 'error' event (ECONNRESET) when editing files #905

Description

@eashish93

What happens

Dev server (bun dev) crashes intermittently while editing source files.
The crash is always an Unhandled 'error' event on a Socket with code
ECONNRESET, originating from Node internals only — no vinext or app
code in the stack:

Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:216:20)
Emitted 'error' event on Socket instance at:
at Socket.onerror (node:internal/streams/readable:1031:14)
at Socket.emit (node:events:508:28)
...
errno: -54, code: 'ECONNRESET', syscall: 'read'

When

Reliably while saving files in the editor, especially when the browser
is mid-request (e.g. RSC stream still flushing) and HMR triggers a
reload. The hint is that two requests just completed (compile: ...,
render: ...), then the next save kills the process.

Why it's a bug

ECONNRESET on a peer-closed socket is normal. It shouldn't crash the
process. Node defaults to throw on unhandled error events, so the
underlying server (HTTP/WS) needs to attach a no-op error handler,
or vinext should attach one at the layer where it owns the socket.

For comparison, Vite handles this in vite's HMR server, and Next.js
ships an 'error' handler on req.socket for the same reason.

Env

  • vinext:
  • Node: v25.2.1
  • Bun: <bun --version>
  • OS: macOS (darwin 25.3.0)

Repro

  1. bun dev
  2. Open the app in browser, navigate around
  3. Edit a source file rapidly (or save mid-navigation)
  4. Server crashes within ~10 saves with the trace above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions