Skip to content

Commit

Permalink
Don't poll websocket on remote expiration
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and indutny-signal committed Feb 14, 2024
1 parent 7b1f23b commit 7c9364b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ts/background.ts
Expand Up @@ -1331,6 +1331,10 @@ export async function startApp(): Promise<void> {
return;
}

if (remotelyExpired) {
return;
}

log.info('reconnectToWebSocket starting...');
await server.reconnect();
});
Expand All @@ -1351,6 +1355,16 @@ export async function startApp(): Promise<void> {
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();
}
Expand Down Expand Up @@ -1553,6 +1567,10 @@ export async function startApp(): Promise<void> {
}

function onOnline() {
if (remotelyExpired) {
return;
}

log.info('online');

window.removeEventListener('online', onOnline);
Expand Down Expand Up @@ -1603,12 +1621,18 @@ export async function startApp(): Promise<void> {

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 {
Expand Down Expand Up @@ -1710,7 +1734,9 @@ export async function startApp(): Promise<void> {
server.registerRequestHandler(messageReceiver);

// If coming here after `offline` event - connect again.
await server.onOnline();
if (!remotelyExpired) {
await server.onOnline();
}

void AttachmentDownloads.start({
logger: log,
Expand Down
1 change: 1 addition & 0 deletions ts/textsecure/Utils.ts
Expand Up @@ -8,6 +8,7 @@ export async function handleStatusCode(status: number): Promise<void> {
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');
}
}

Expand Down

0 comments on commit 7c9364b

Please sign in to comment.