From d31a4d5d9194bf159416f0ec9fb4b306d6a8011f Mon Sep 17 00:00:00 2001 From: trevor-signal <131492920+trevor-signal@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:16:05 -0400 Subject: [PATCH] Close websocket if request times out --- ts/textsecure/WebsocketResources.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/ts/textsecure/WebsocketResources.ts b/ts/textsecure/WebsocketResources.ts index e79518d463..166a20dd13 100644 --- a/ts/textsecure/WebsocketResources.ts +++ b/ts/textsecure/WebsocketResources.ts @@ -656,13 +656,10 @@ export default class WebSocketResource strictAssert(!this.shuttingDown, 'Cannot send request, shutting down'); this.addActive(idString); const promise = new Promise((resolve, reject) => { - const sentAt = Date.now(); - let timedOut = false; - let timer = options.timeout ? Timers.setTimeout(() => { - timedOut = true; this.removeActive(idString); + this.close(3001, 'Request timed out'); reject(new Error(`Request timed out; id: [${idString}]`)); }, options.timeout) : undefined; @@ -672,16 +669,8 @@ export default class WebSocketResource Timers.clearTimeout(timer); timer = undefined; } - if (timedOut) { - log.warn( - `${this.logId}: Response received after timeout; ` + - `id: [${idString}], path: [${options.path}], ` + - `response time: ${Date.now() - sentAt}ms` - ); - } else { - // Reset keepalive when an on-time response arrives - this.keepalive?.reset(); - } + + this.keepalive?.reset(); this.removeActive(idString); resolve(result); });