fix(server): use the recommended connection handler from @fastify/websocket to avoid triggering stream backpressure (#5530) #5532
+67
−32
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.
Closes #5530
🎯 Changes
I've moved connection event handler creation into a separate function to allow for it being used directly inside of the
@fastify/websocket
connection callback.Also, I deliberately left prefix handling in
applyWSSHandler
, so we can leave routing to fastify itself.For future consideration - might be worth using something in line of the following to stay compatible with future versions of
@fastify/websocket
(if my changes get approved) alongside with backwards compatibility:There's a chance they might end up just exposing the raw
WebSocket
object on their end from the handler, but this isn't guaranteed to happen.Update: I've submitted a PR to
@fastify/websocket
as well, might be worth checking out with regards to compatibility: fastify/fastify-websocket#290✅ Checklist