From abe9aa1fdc70942bcf36bf544001ef4189b5c06a Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 18 Nov 2024 20:40:08 +0000 Subject: [PATCH] fix acceleration websocket timeout loop --- backend/src/api/services/acceleration.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/api/services/acceleration.ts b/backend/src/api/services/acceleration.ts index e18bcf464..e4edab791 100644 --- a/backend/src/api/services/acceleration.ts +++ b/backend/src/api/services/acceleration.ts @@ -247,6 +247,7 @@ class AccelerationApi { if (!this.ws) { this.ws = new WebSocket(this.websocketPath); this.websocketConnected = true; + this.lastPing = 0; this.ws.on('open', () => { logger.info(`Acceleration websocket opened to ${this.websocketPath}`); @@ -286,12 +287,13 @@ class AccelerationApi { this.lastPong = Date.now(); }); } else { - if (this.lastPing > this.lastPong && Date.now() - this.lastPing > 10000) { + if (this.lastPing && this.lastPing > this.lastPong && (Date.now() - this.lastPing > 10000)) { logger.warn('No pong received within 10 seconds, terminating connection'); this.ws.terminate(); this.ws = null; this.websocketConnected = false; - } else if (Date.now() - this.lastPing > 30000) { + this.lastPing = 0; + } else if (!this.lastPing || (Date.now() - this.lastPing > 30000)) { logger.debug('sending ping to acceleration websocket server'); this.ws.ping(); this.lastPing = Date.now();