Don't poll websocket on remote expiration

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-02-14 14:20:33 -06:00 committed by GitHub
parent fc7e24f5f9
commit d5aefc83f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View file

@ -1331,6 +1331,10 @@ export async function startApp(): Promise<void> {
return;
}
if (remotelyExpired) {
return;
}
log.info('reconnectToWebSocket starting...');
await server.reconnect();
});
@ -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();
}
@ -1553,6 +1567,10 @@ export async function startApp(): Promise<void> {
}
function onOnline() {
if (remotelyExpired) {
return;
}
log.info('online');
window.removeEventListener('online', onOnline);
@ -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 {
@ -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,

View file

@ -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');
}
}