Repository navigation
fix(vite): suppress errors after client disconnect - #4708
Conversation
|
@AdarshYadav9 is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks for the fix! One gap remains on HTTPS dev servers. When Checked on Node.js 26.10.0 with { resDestroyed: undefined, streamDestroyed: true, reqAborted: true, writableEnded: false }
// res.destroyed, res.stream.destroyed, req.aborted, res.writableEndedA check that covers HTTP/1.1 and HTTP/2 (what we use in a dev-server error middleware for now): function isClientGone(req, res) {
if (req.aborted || req.errored) return true;
if (res.writableEnded) return false;
if (req.stream?.destroyed) return true; // HTTP/2 compatibility API
return (req.destroyed && !req.complete) || res.destroyed || Boolean(req.socket?.destroyed);
}With it, server-function POSTs dropped after 0 to 50 ms over HTTP/1.1 and HTTP/2 stopped reaching the open page: 6 of 84 did before, 0 of 84 after. |
🔗 Linked issue
Resolves #4697
❓ Type of change:-
Description
When a client aborts a POST request while the body is still being received, Node.js emits an
Error: abortedon the request stream. Nitro's Vite development middleware currently forwards this error to Vite vianext(error), which logs an internal server error and broadcasts the error overlay to connected browser tabs, even though the client has already disconnected and no response can be sent.Fix —
src/build/vite/dev.ts:The added
nodeRes.destroyedcheck prevents the aborted-request error from being forwarded to Vite when the client connection has already been terminated.nodeRes.destroyedis used instead ofnodeReq.destroyedbecause the request stream can become destroyed after the request body has been fully consumed while the client connection is still active. UsingnodeReq.destroyedcould therefore suppress legitimate errors.Other errors continue to be forwarded to Vite normally.
This change is intentionally scoped to the Vite development middleware and does not affect production request handling.
📝 Checklist