fix: remove custom server upgrade listener on close - #379
Open
lprnmns wants to merge 1 commit into
Open
Conversation
Signed-off-by: lprnmns <manasalperen@gmail.com>
lprnmns
marked this pull request as ready for review
August 31, 2026 16:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.