Skip to content

Commit 7232473

Browse files
author
Nick Schwab
committed
+ stop connection interval upon different client termination events
1 parent a516d38 commit 7232473

2 files changed

Lines changed: 37 additions & 8 deletions

File tree

lib/node/dist/index.js

Lines changed: 21 additions & 4 deletions
Large diffs are not rendered by default.

lib/node/src/transport/WebSocketServer.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class WebSocketServer extends TransportBase {
6464
// Event listener for a closed connection
6565
client.on('close', () => {
6666
console.log('server received close event');
67+
this._stopConnectionLostInterval();
6768
if (this._transportCallback !== null) {
6869
this._transportCallback.onConnectionTerminated();
6970
}
@@ -93,6 +94,7 @@ class WebSocketServer extends TransportBase {
9394
this._connectionLostInterval = setInterval(() => {
9495
if (client.isAlive === false) {
9596
console.log('server deemed client dead');
97+
this._stopConnectionLostInterval();
9698
return client.terminate();
9799
}
98100

@@ -115,10 +117,7 @@ class WebSocketServer extends TransportBase {
115117
stop () {
116118
const client = this._transportConfig.getClient();
117119

118-
if (this._connectionLostInterval !== null) {
119-
clearInterval(this._connectionLostInterval);
120-
}
121-
120+
this._stopConnectionLostInterval();
122121
client.terminate();
123122

124123
return this;
@@ -137,6 +136,19 @@ class WebSocketServer extends TransportBase {
137136
return this;
138137
}
139138

139+
/**
140+
* Stop the connection lost interval if one is defined
141+
* @return {WebSocketServer}
142+
* @private
143+
*/
144+
_stopConnectionLostInterval () {
145+
if (this._connectionLostInterval !== null) {
146+
clearInterval(this._connectionLostInterval);
147+
}
148+
149+
return this;
150+
}
151+
140152
/**
141153
* This is called whenever a new message comes in
142154
* @param {MessageEvent} message

0 commit comments

Comments
 (0)