Repository navigation
fix(dev): do not leak a rejection when a proxied upgrade fails - #4494
Conversation
|
@kedrzu is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
This conflicts with #4788 now. After rebasing, Triaged with AI assistance. |
`DevServer.handleUpgrade` is async and both callers drop the promise it
returns: the `upgrade` method handed out by `createDevServer`, and the
`server.on("upgrade")` listener in `listen`. It rejects when no worker is
available, and — far more often — from `NodeDevWorker.handleUpgrade`,
which returns `proxy.ws(...)` unawaited. Replacing the dev worker kills
every websocket proxied to it, so that promise rejects with `ECONNRESET`
and nothing is there to catch it.
For Nitro alone that is a stray unhandled rejection. Under Nuxt it ends
the session, because the CLI treats any unhandled rejection as fatal and
restarts the dev server; with a client that reconnects it loops.
Make `handleUpgrade` never reject. There is nothing left to reply with
once a handshake is in flight, so a failed upgrade closes the socket, and
only errors that are not a peer disconnect are reported.
Resolves nitrojs#4493
Co-Authored-By: Claude Opus 5 <[email protected]>
d53479b to
27d131d
Compare
🔗 Linked issue
Resolves #4493
❓ Type of change
📚 Description
DevServer.handleUpgradeis async, and both callers drop its promise: theupgradelistener inlisten(), and the exportedupgrade(), which Nuxt calls without awaiting.It rejects whenever a proxied websocket dies. httpxy's
ws()promise stays pending for the whole life of the socket and rejects withECONNRESETwhen either side resets it, for example a browser refresh or a client abort. With no worker,handleUpgradealso threw a 503createError. Either way the result was an unhandled rejection. Under Nuxt that restarts the dev server (nuxt/cli#247, nuxt/cli#968, nuxt/cli#994).Changes:
handleUpgradenever rejects. A failed upgrade destroys the socket. Peer disconnects (ECONNRESET,ECONNABORTED,EPIPE,ERR_STREAM_PREMATURE_CLOSE) are not logged; other errors are logged withconsola.warn.HTTP/1.1 503response and the socket is closed. This isn't logged, because the build error is already reported and reconnecting clients would flood the console.devProxywebsocket routes (fix(dev): proxy websocket upgrades fordevProxyroutes withws#4788) skip the warning on peer disconnects too.DevWorker["handleUpgrade"]is typedPromise<void> | void, which is whatNodeDevWorkeralready returns.test/dev-shutdowncovering: client resets of an established websocket, worker reload with an open websocket, and the 503 afterdev:error. Onv2without this fix it fails with 3ECONNRESETunhandled rejections.mainhas the same pattern insrc/dev/server.ts, so it needs its own PR.📝 Checklist
🤖 Generated with AI assistant