Terminate connection on timeout

If a connection has timed out the most likely cause is the connection
going stale, in which case calling close could take up to 30 seconds
before the ws lib gives up on waiting for the close message.  Terminate
the connection instead on the Node.js side.  Note that Firefox does not
permit applications from closing connections with a code other than
1000, or in the range 3000-4999.
This commit is contained in:
Hornwitser committed 2021-09-28 21:24:42 +02:00
1 parent f529457f96
commit 4a72c14b74
3 files changed
+10 -14

No files matched your search

+6 -1
View File
@@ -73,7 +73,12 @@ class WebSocketBaseConnector extends events.EventEmitter {
this._check("connected");
if (Date.now() - this._lastHeartbeat > 2000 * this._heartbeatInterval) {
logger.verbose("Connector | closing after heartbeat timed out");
this._socket.close(1008, "Heartbeat timeout");
// eslint-disable-next-line node/no-process-env
if (process.env.APP_ENV === "browser") {
this._socket.close(4008, "Heartbeat timeout");
} else {
this._socket.terminate();
}
} else {
this._socket.send(JSON.stringify({