mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #911] [MERGED] fix(dev): swallow socket errors so peer disconnects don't crash dev server #941
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#941
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/911
Author: @james-elicx
Created: 4/26/2026
Status: ✅ Merged
Merged: 4/26/2026
Merged by: @james-elicx
Base:
main← Head:claude/condescending-agnesi-dc8089📝 Commits (1)
591f59dfix(dev): swallow socket errors so peer disconnects don't crash dev server📊 Changes
1 file changed (+12 additions, -0 deletions)
View changed files
📝
packages/vinext/src/index.ts(+12 -0)📄 Description
Summary
Closes #905.
bun devcrashes intermittently with an unhandledECONNRESETon aSocketwhen files are saved mid-request — typically when HMR triggers a reload while an RSC stream is still flushing. The trace has no vinext or app frames; it comes straight from Node internals. Node's default behavior on an unhandled'error'event is to throw, and the dev server doesn't currently attach a listener on the request/response sockets, so a peer disconnect duringres.writetakes the process down.This patch attaches a no-op
'error'listener on every connection inconfigureServer. The error is still surfaced to the writing stream as a normal write failure — the listener only neutralises Node's default throw, it doesn't hide real bugs.Connection-level (rather than per-request) was chosen because vinext doesn't own all the dev middlewares: App Router routing goes through
@vitejs/plugin-rsc, which streams its own response. One guard at the connection level covers both routers and any future streaming surface.Dev-only — production runs as a Cloudflare Worker where the runtime owns socket lifecycle, and
prod-server.tsalready attaches an error handler on the request stream where it needs one.Prior art
Both Vite and Next.js attach the same kind of guard for the same reason:
req/resper request: router-server.ts#L289-L294Test plan
vp checkpasses (format, lint, typecheck)bun dev, navigate around the example app, save source files rapidly while the browser is mid-RSC-stream — server no longer crashes withUnhandled 'error' event/ECONNRESET🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.