-
Notifications
You must be signed in to change notification settings - Fork 342
Clear WebSocket event listeners on close. #615
Clear WebSocket event listeners on close. #615
Conversation
@tretne: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
a0737a9
to
1ed7bca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tretne!
@@ -167,6 +167,10 @@ export class SubscriptionClient { | |||
} | |||
|
|||
this.client.close(); | |||
this.client.onopen = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
After this change we started getting the following error in our app:
[TypeError: Cannot set property 'onopen' of null]
e.close (webpack://[name]/node_modules/subscriptions-transport-ws/dist/client.js:126:33)
close (webpack://[name]/node_modules/subscriptions-transport-ws/dist/client.js:477:22)
I believe it is due to some race conditioning where two simultaneous calls are made to close()
.
Unfortunately, I don't have a repro for this bug so it's tricky to tell exactly what went wrong.
The call stack starts in the this.client.onclose
handler (see https://github.com/apollographql/subscriptions-transport-ws/blob/v0.9.18/src/client.ts#L580-L584).
Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tretne I think this Cannot set property 'onopen' of null
error happens when close() is called synchronously from within close() in a nested way (my guess - during this.unsubscribeAll() call - the subscription handlers may have some cleanups within themselves which close the the client).
The solution would be to either:
- have one more check before using this.client on L169 and below, or
- assign null to this.client early (if it's applicable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think @dko-slapdash is right -- I'm able to reproduce this pretty easily by loading my app with the network down.
e.g.
- Host backend locally
- Point ngrok at the backend
- Point the client at ngrok
Refresh the app.
A solution is:
const client = this.client
this.client = null
// rest of cleanup ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolves #581
TODO: