Repository navigation
fix(vite): suppress aborted errors on HTTP/2 client disconnect - #4773
Conversation
Fixes nitrojs#4772 Signed-off-by: Liang Xu <[email protected]>
|
@lx3133584 is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 1
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
commit: |
…http2-client-disconnect
Replace the mocked unit test with a dev server regression test, and keep the helper internal.
🔗 Linked issue
Resolves #4772
❓ Type of change
📚 Description
Problem
When running Vite dev server over HTTP/2 (e.g. when
server.httpsis configured, or under an HTTP/2 reverse proxy), client request cancellation (such as navigation during a pending POST body upload) causes Vite error middleware to receive an aborted request error and logInternal server error: This operation was aborted, broadcasting error overlays to connected browser tabs. Over HTTP/1.1 this was suppressed in #4708, but HTTP/2 remained unhandled.Root Cause
In Node.js
node:http2,Http2ServerResponseinstances do not expose adestroyedproperty directly (it evaluates toundefined), whereas their underlyingServerHttp2Streaminstance (res.stream) tracks cancellation viares.stream.destroyed. Insrc/build/vite/dev.ts, the checkif (nodeRes.destroyed) return;evaluates toundefined(falsy) on HTTP/2 responses, causing client-aborted errors to be forwarded tonext(error).Fix
Introduced
isResponseDestroyed(res)insrc/build/vite/dev.tsthat checks bothres.destroyed(for HTTP/1.1ServerResponse) and("stream" in res && res.stream?.destroyed)(for HTTP/2Http2ServerResponse). When either is destroyed, the error is safely suppressed from forwarding to Vite.Testing
Added unit tests in
test/unit/vite-dev-client-disconnect.test.tsverifyingisResponseDestroyedcorrectly identifies destroyed and active states for both standard Node.jsServerResponseand HTTP/2Http2ServerResponsestream objects.📝 Checklist