fix(@nestjs/graphql): need to properly close websocket servers #2366
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently, we do not properly shutdown the websocket transports (
graphql-ws
&subscriptions-transport-ws
).It looks like there was some logic removed here (bottom of the graphql-ws-subscription.service.ts diff) that mimics graphql-ws's tear-down logic. And that the net new logic from that diff dupe'd this same behavior (just sending a
1001
) for tearing downsubscriptions-transport-ws
, which doesn't seem reflective of what ApolloServer was doing when they called.close()
(back in V2) on the now-deprecated subscriptions-transport-ws's close handler.I noticed the behavior when my client was receiving the manually sent
1001
, but was still able to immediately reconnect. This led me to discovering that we were just sending that code without doing anything else beyond that. I have async tear-down logic in my ownOnModuleDestroy
's, so the client being able to reconnect and request resources that I was actively trying to tear-down led to the discovery of these issues.What is the new behavior?
All this to say, I think it makes the most sense to defer the tear-down logic to the libraries/protocols themselves. I am very much open to feedback and discussion on this 馃憤馃徎.
Does this PR introduce a breaking change?
If folks were relying on the server not being properly shut down, then maybe? My gut says no, but interested in what others think.
Other information