Prevent beat timeout from disconnecting newly connecting sockets #304
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.
Issue
Occasionally
client.connect()
errors withRequest failed - server disconnected
milliseconds after initiating the connection.Root cause
This error occurs because for a short lived time a socket is established on the server but the
nes
"hello" handshake message has not been processed sosocket._active()
will returnfalse
due to the fact thatthis._pinged
is false. Once the "hello" message is processed the socket is correctly identified as active.If the beat timeout occurs between the websocket being added to to the sockets collection but before the "hello" is processed the beat timeout logic will disconnect the socket.
Proposed fix
The proposed fix is to allow a grace period in which newly created sockets are not disconnected by the beat timeout.
Testing
Being a race condition it is difficult to test but the unit test added will fail repeatedly if my logic is removed.