Repository navigation
fix(node): add the upgrade listener once - #212
boluwatifeajayi wants to merge 2 commits into
Conversation
The plugin wrapped server.serve() and added a new upgrade listener to the node server on every call, so a repeated serve() made each websocket upgrade run through the handler several times. Only add the listener the first time.
|
@boluwatifeajayi is attempting to deploy a commit to the unjs Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…rade listener once - track raw upgrade sockets in the srvx plugin and destroy them on `close(true)`, so an upgrade whose hook is still pending can't complete afterwards and keep the server open - add the `upgrade` listener only once across repeated `serve()` calls (fixes #205, supersedes #212) - respect `silent` when logging failed upgrades Co-authored-by: boluwatifeajayi <bolu4good@gmail.com>
|
Thanks @boluwatifeajayi! This fix is folded into #225 (with you as co-author on the commit), since both PRs touched the same |
…eers on forced server close (#225) * fix(node): catch `handleUpgrade` rejections and terminate WebSocket peers on forced server close - catch rejections from `handleUpgrade` itself (e.g. writing the rejection response) in the srvx plugin: destroy the socket and log the error instead of raising an unhandled rejection - `close(true)` now terminates crossws peers and stops the idle sweep (Node's `closeAllConnections()` doesn't reach upgraded sockets); a graceful `close()` leaves them open, matching srvx docs and Bun - build the upgrade `NodeRequest` with the server's `trustProxy` and `waitUntil`, like srvx does for regular requests * fix(node): terminate pending upgrades on forced close and add the upgrade listener once - track raw upgrade sockets in the srvx plugin and destroy them on `close(true)`, so an upgrade whose hook is still pending can't complete afterwards and keep the server open - add the `upgrade` listener only once across repeated `serve()` calls (fixes #205, supersedes #212) - respect `silent` when logging failed upgrades Co-authored-by: boluwatifeajayi <bolu4good@gmail.com> --------- Co-authored-by: Pooya Parsa <pooya@pi0.io> Co-authored-by: boluwatifeajayi <bolu4good@gmail.com>
Fixes #205 (the issue is filed under unjs/crossws, which now lives here).
The node server plugin replaces
server.servewith a function that adds anupgradelistener to the node http server and then calls the originalserve. The listener was added on every call, so with repeatedserve()calls each websocket upgrade went throughws.handleUpgradeseveral times, which is the unexpected behaviour from the issue.The issue suggests either doing nothing or throwing on a repeated call. I went with not adding the listener again and still calling the original
serve, so what srvx does for a second call (error or not) stays the same and the plugin does not decide that on its own. If you would rather throw here, that is a small change.Added a test in
test/unit.test.tsthat installs the plugin on a fake server, callsserve()three times and checks the upgrade listener count is one and the originalserveran three times. It fails on main.pnpm lintpasses. The full vitest run has the same 33 failures with and without this change on my machine (they need the deno and bun runtimes and the proxy setup), and the unit test file passes.Summary by CodeRabbit