From cd3d3dc8a61c465a46c5be5cd1424ffb1eeb7c48 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:37:47 -0800 Subject: [PATCH] Don't poll websocket on remote expiration --- ts/background.ts | 28 +++++++++++++++++++++++++++- ts/textsecure/Utils.ts | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ts/background.ts b/ts/background.ts index bdbde412d0ec..c228400d9511 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -1332,6 +1332,10 @@ export async function startApp(): Promise { return; } + if (remotelyExpired) { + return; + } + log.info('reconnectToWebSocket starting...'); await server.reconnect(); }); @@ -1352,6 +1356,16 @@ export async function startApp(): Promise { void unlinkAndDisconnect(); }); + window.Whisper.events.on('httpResponse499', () => { + if (remotelyExpired) { + return; + } + + log.warn('background: remote expiration detected, disabling reconnects'); + remotelyExpired = true; + onOffline(); + }); + async function runStorageService() { StorageService.enableStorageService(); } @@ -1554,6 +1568,10 @@ export async function startApp(): Promise { } function onOnline() { + if (remotelyExpired) { + return; + } + log.info('online'); window.removeEventListener('online', onOnline); @@ -1604,12 +1622,18 @@ export async function startApp(): Promise { let connectCount = 0; let connecting = false; + let remotelyExpired = false; async function connect(firstRun?: boolean) { if (connecting) { log.warn('connect already running', { connectCount }); return; } + if (remotelyExpired) { + log.warn('remotely expired, not reconnecting'); + return; + } + strictAssert(server !== undefined, 'WebAPI not connected'); try { @@ -1711,7 +1735,9 @@ export async function startApp(): Promise { server.registerRequestHandler(messageReceiver); // If coming here after `offline` event - connect again. - await server.onOnline(); + if (!remotelyExpired) { + await server.onOnline(); + } void AttachmentDownloads.start({ logger: log, diff --git a/ts/textsecure/Utils.ts b/ts/textsecure/Utils.ts index 67a1a8e941ad..bb7b73dfc905 100644 --- a/ts/textsecure/Utils.ts +++ b/ts/textsecure/Utils.ts @@ -8,6 +8,7 @@ export async function handleStatusCode(status: number): Promise { if (status === 499) { log.error('Got 499 from Signal Server. Build is expired.'); await window.storage.put('remoteBuildExpiration', Date.now()); + window.Whisper.events.trigger('httpResponse499'); } }