Conversation
Signed-off-by: lprnmns <manasalperen@gmail.com>
|
Independent confirmation of this from a different symptom path. Setup: a never-listened before register = 0 So the listener installed by the plugin survives close. With a custom Measured while running the plugin alongside Vite's HMR websocket in custom dev setup; with this fix that setup needs no custom |
Problem
When
@fastify/websocketis configured withoptions.server, it registers itsupgradelistener on that supplied server. Onfastify.close(), cleanup currently removes the listener fromfastify.serverinstead. If the supplied server remains running, later upgrade requests are routed through the closed Fastify instance and receive a stale 503 response.Fix
Remove the plugin upgrade listener from
websocketListenServer, the same HTTP/S server selected during setup. This preserves unrelated upgrade listeners on a shared server.Tests
node --test --test-name-pattern="custom server on close" test/base.test.js— failed before the fix with1 !== 0; passed after the fix (1 test)npm test— passed; 61 unit tests, 100% reported coverage, 65 TypeScript assertionsnpm run lint— passednode --check index.js && node --check test/base.test.js && git diff --check— passednpm run benchmark --if-present— passed; no benchmark script is definedCompatibility
This changes cleanup only for the supported pre-created HTTP/S server option. It does not change route handling or remove listeners owned by other consumers.
Related issue
Independent current-branch reproduction; no existing issue or pull request matched after searches for custom server, external server, server option, upgrade listener, listener cleanup, and Fastify close behavior.