Fix shutdown with bad network connectivity
This commit is contained in:
parent
dd5b66039d
commit
41e44a8787
3 changed files with 46 additions and 11 deletions
|
@ -162,7 +162,7 @@ import { StartupQueue } from './util/StartupQueue';
|
|||
import { showConfirmationDialog } from './util/showConfirmationDialog';
|
||||
import { onCallEventSync } from './util/onCallEventSync';
|
||||
import { sleeper } from './util/sleeper';
|
||||
import { DAY, HOUR, MINUTE } from './util/durations';
|
||||
import { DAY, HOUR, SECOND } from './util/durations';
|
||||
import { copyDataMessageIntoMessage } from './util/copyDataMessageIntoMessage';
|
||||
import {
|
||||
flushMessageCounter,
|
||||
|
@ -798,7 +798,7 @@ export async function startApp(): Promise<void> {
|
|||
);
|
||||
timeout = undefined;
|
||||
resolve();
|
||||
}, 1 * MINUTE);
|
||||
}, 10 * SECOND);
|
||||
}),
|
||||
]);
|
||||
if (timeout) {
|
||||
|
|
|
@ -122,14 +122,14 @@ export class ProfileService {
|
|||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
isRecord(error) &&
|
||||
'code' in error &&
|
||||
(error.code === 413 || error.code === 429)
|
||||
) {
|
||||
this.clearAll(`got ${error.code} from server`);
|
||||
const time = findRetryAfterTimeFromError(error);
|
||||
void this.pause(time);
|
||||
if (isRecord(error) && 'code' in error) {
|
||||
if (error.code === -1) {
|
||||
this.clearAll('Failed to connect to the server');
|
||||
} else if (error.code === 413 || error.code === 429) {
|
||||
this.clearAll(`got ${error.code} from server`);
|
||||
const time = findRetryAfterTimeFromError(error);
|
||||
void this.pause(time);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.jobsByConversationId.delete(conversationId);
|
||||
|
@ -525,7 +525,7 @@ async function doGetProfile(c: ConversationModel): Promise<void> {
|
|||
? `code: ${error.code}`
|
||||
: Errors.toLogFormat(error)
|
||||
);
|
||||
return;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,5 +154,40 @@ describe('util/profiles', () => {
|
|||
assert.strictEqual(runCount, 3, 'after await');
|
||||
});
|
||||
}
|
||||
|
||||
it('clears all outstanding jobs if we get a -1', async () => {
|
||||
let runCount = 0;
|
||||
const getProfileWhichThrows = async () => {
|
||||
runCount += 1;
|
||||
const error = new HTTPError('fake -1', {
|
||||
code: -1,
|
||||
headers: {},
|
||||
});
|
||||
throw error;
|
||||
};
|
||||
const service = new ProfileService(getProfileWhichThrows);
|
||||
|
||||
// Queued and immediately started due to concurrency = 3
|
||||
const promise1 = service.get(SERVICE_ID_1);
|
||||
const promise2 = service.get(SERVICE_ID_2);
|
||||
const promise3 = service.get(SERVICE_ID_3);
|
||||
|
||||
// Never started, but queued
|
||||
const promise4 = service.get(SERVICE_ID_4);
|
||||
|
||||
assert.strictEqual(runCount, 3, 'before await');
|
||||
|
||||
await assert.isRejected(promise1, 'fake -1');
|
||||
|
||||
// Queued, because we aren't pausing
|
||||
const promise5 = service.get(SERVICE_ID_5);
|
||||
|
||||
await assert.isRejected(promise2, 'job cancelled');
|
||||
await assert.isRejected(promise3, 'job cancelled');
|
||||
await assert.isRejected(promise4, 'job cancelled');
|
||||
await assert.isRejected(promise5, 'fake -1');
|
||||
|
||||
assert.strictEqual(runCount, 4, 'after await');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue