Don't poll websocket on remote expiration

This commit is contained in:
Fedor Indutny
2024-02-14 10:37:47 -08:00
committed by GitHub
parent fe27910221
commit cd3d3dc8a6
2 changed files with 28 additions and 1 deletions

View File

@@ -1332,6 +1332,10 @@ export async function startApp(): Promise<void> {
return;
}
if (remotelyExpired) {
return;
}
log.info('reconnectToWebSocket starting...');
await server.reconnect();
});
@@ -1352,6 +1356,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();
}
@@ -1554,6 +1568,10 @@ export async function startApp(): Promise<void> {
}
function onOnline() {
if (remotelyExpired) {
return;
}
log.info('online');
window.removeEventListener('online', onOnline);
@@ -1604,12 +1622,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 {
@@ -1711,7 +1735,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');
}
}