-
-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix multiple sockets on reconnection #698
Fix multiple sockets on reconnection #698
Conversation
Thanks for the PR, this is an interesting bug! Why do you need |
Yup, fixed |
Thanks a lot for the fix & detailed reproduction steps, and even more thanks for the video :) Merging this 💪 |
I customized a WebSocketPolyfill for encryption and decryption of websocket data:
But I noticed that this change replaced onmessage with addEventListener. How will I hook the returned information? |
@xymfs you can override addEventListener over here and capture the listener for |
Thanks for the tip, it works fine after modification
|
Currently websocket listeners are not cleaned up on disconnection and
createWebSocketConnection
is called from multiple sources which results in multiple sockets to be created every time a user comes back online from sleep or there is a disruption in connectivity.Steps to reproduce:
messageReconnectTimeout
value (hearbeat failure).The online event listener also calls
createWebSocketConnection
After this change only 1 socket is active at any given time. This PR is just a reference to fix the underlying issue. It can be fixed in multiple ways. I think the event emitter should be bound with the lifecycle of the websocket. Currently even stale websockets emit events that are handled with the latest context.
Ran lint:fix so there are some extra lint changes.
attachWebSocketListeners
stores the reference of attached listeners.cleanupWebSocket
removes the listeners before resetting reference of the websocket.online
event listener has been removed as it leads to a duplicate socket. Once connection has been established, sockets are retried anyway infinite times. If initial connection fails, the retry wrapper takes over and attempts only the number of times that have been set.Added an identifier to the socket instance.
Before:
Multiple.Connections.720.mov
After: