From ef498b55edf43f82c6da39253872e64229121dd8 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 11 Nov 2024 16:59:08 +0000 Subject: [PATCH] reset acceleration websocket if unresponsive --- backend/src/api/services/acceleration.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/api/services/acceleration.ts b/backend/src/api/services/acceleration.ts index cb84ab8dc..e86f0f200 100644 --- a/backend/src/api/services/acceleration.ts +++ b/backend/src/api/services/acceleration.ts @@ -50,6 +50,7 @@ class AccelerationApi { private _accelerations: Record = {}; private lastPoll = 0; private lastPing = 0; + private lastPong = 0; private forcePoll = false; private myAccelerations: Record = {}; @@ -284,7 +285,12 @@ class AccelerationApi { logger.debug('received pong from acceleration websocket server'); }); } else { - if (Date.now() - this.lastPing > 30000) { + if (this.lastPing > this.lastPong && Date.now() - this.lastPing > 5000) { + logger.warn('No pong received within 5 seconds, terminating connection'); + this.ws.terminate(); + this.ws = null; + this.websocketConnected = false; + } else if (Date.now() - this.lastPing > 30000) { logger.debug('sending ping to acceleration websocket server'); this.ws.ping(); this.lastPing = Date.now();