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
bun dev
- Open the app in browser, navigate around
- Edit a source file rapidly (or save mid-navigation)
- Server crashes within ~10 saves with the trace above
What happens
Dev server (
bun dev) crashes intermittently while editing source files.The crash is always an
Unhandled 'error' eventon a Socket with codeECONNRESET, originating from Node internals only — no vinext or appcode 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
throwon unhandlederrorevents, so theunderlying 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 onreq.socketfor the same reason.Env
Repro
bun dev