Skip to content

Commit 94bfef8

Browse files
committed
fix: WebSocketConnection timeout executes properly now
1 parent 18e3844 commit 94bfef8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/WebSocketConnection.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ class WebSocketConnection {
678678
if (this.config.keepAliveIntervalTime != null) {
679679
this.startKeepAliveIntervalTimer(this.config.keepAliveIntervalTime);
680680
}
681+
if (this.config.keepAliveTimeoutTime != null) {
682+
this.setKeepAliveTimeoutTimer();
683+
}
681684

682685
this.logger.info(`Started ${this.constructor.name}`);
683686
}
@@ -788,6 +791,7 @@ class WebSocketConnection {
788791
} = {}) {
789792
this.logger.info(`Stop ${this.constructor.name}`);
790793
this.stopKeepAliveIntervalTimer();
794+
this.stopKeepAliveTimeoutTimer();
791795
if (
792796
this.socket.readyState !== ws.CLOSING &&
793797
this.socket.readyState !== ws.CLOSED
@@ -837,7 +841,6 @@ class WebSocketConnection {
837841
this.socket.off('ping', this.handleSocketPing);
838842
this.socket.off('pong', this.handleSocketPong);
839843
this.socket.off('error', this.handleSocketError);
840-
this.stopKeepAliveTimeoutTimer();
841844

842845
this.logger.info(`Stopped ${this.constructor.name}`);
843846
}
@@ -866,6 +869,7 @@ class WebSocketConnection {
866869
this.keepAliveTimeOutTimer.reset(timeout);
867870
} else {
868871
logger.debug(`timeout created with delay ${timeout}`);
872+
this.keepAliveTimeOutTimer?.cancel();
869873
this.keepAliveTimeOutTimer = new Timer({
870874
delay: timeout,
871875
handler: keepAliveTimeOutHandler,
@@ -877,7 +881,7 @@ class WebSocketConnection {
877881
* Stops the keep alive interval timer
878882
*/
879883
protected stopKeepAliveTimeoutTimer(): void {
880-
this.keepAliveIntervalTimer?.cancel();
884+
this.keepAliveTimeOutTimer?.cancel();
881885
}
882886

883887
protected startKeepAliveIntervalTimer(ms: number): void {

0 commit comments

Comments
 (0)