Fix close during reconnect wait period

If the connect close method is called while the connection is waiting
for a reconnection attempt then the attempt is cancelled but the close
method then erroneously waited for a close event that would never
happen.  Fix by resetting the connector and rasing the close event in
the close method if it's in the waiting for reconnect state.
This commit is contained in:
Hornwitser committed 2021-03-06 18:38:30 +01:00
1 parent 85a984734b
commit d6f09f4c1a
2 files changed
+15

No files matched your search

+7
View File
@@ -211,6 +211,13 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
if (this._reconnectId) {
clearTimeout(this._reconnectId);
this._reconnectId = null;
this._lastReceivedSeq = null;
this._sessionToken = null;
this._sendBuffer.length = 0;
this._state = "new";
this._connected = false;
this.emit("close");
return;
}
this.stopHeartbeat();
+8
View File
@@ -53,4 +53,12 @@ describe("Integration of lib/link", function() {
await events.once(controlConnector, "invalidate");
await events.once(controlConnector, "connect");
});
it("should properly close connector if close is called during reconnect wait", async function() {
controlConnector._socket.close(1008, "Test");
controlConnector.once("drop", () => {
controlConnector.close();
});
await events.once(controlConnector, "close");
});
});