Closed seanjb closed 2 months ago
:tada: This PR is included in version 2.3.1-beta.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
:tada: This PR is included in version 2.3.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
The connection closure method sets the readyState to CLOSING and emits a close event to the socket, then sets the ready state to CLOSED.
However, due to a race condition, the readyState is already at the state of CLOSED when the socket close method is triggered. This causes an exception and a reconnection attempt. As reported in #100
This fix ensures the connectionTimer is cleared before emitting the close event, and updates the socket close handler to only throw an exception if the closure was unexpected (e.g. readyState is not CLOSED and the connectionTimer was not previously destroyed).
Tests added to ensure the new logic is closing the connection correctly. Removing the changes to the connection.ts method the tests correctly catch the closure exception and fail.