mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Fix restarting provisioner loop
This commit is contained in:
@@ -236,6 +236,7 @@ export class Provisioner {
|
||||
}
|
||||
log.info(`Provisioner: stopping, reason=${reason}`);
|
||||
|
||||
this.#sockets = [];
|
||||
this.#abortController?.abort();
|
||||
this.#abortController = undefined;
|
||||
this.#isRunning = false;
|
||||
@@ -272,6 +273,11 @@ export class Provisioner {
|
||||
|
||||
log.info(`${logId}: connected, refreshing in ${delay}ms`);
|
||||
} catch (error) {
|
||||
// New loop is running
|
||||
if (signal !== this.#abortController?.signal) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The only active socket has failed, notify subscribers and shutdown
|
||||
if (this.#sockets.length === 0) {
|
||||
if (error === TIMEOUT_ERROR || error instanceof ConnectTimeoutError) {
|
||||
@@ -314,6 +320,11 @@ export class Provisioner {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await sleep(delay, signal);
|
||||
} catch (error) {
|
||||
// New loop is running
|
||||
if (signal !== this.#abortController?.signal) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Sleep aborted
|
||||
strictAssert(
|
||||
this.#subscribers.size === 0,
|
||||
@@ -439,23 +450,29 @@ export class Provisioner {
|
||||
code: number,
|
||||
reason: string
|
||||
): void {
|
||||
log.info(`Provisioner: socket closed, code=${code}, reason=${reason}`);
|
||||
|
||||
const index = this.#sockets.indexOf(resource);
|
||||
if (index === -1) {
|
||||
log.info(
|
||||
'Provisioner: ignoring socket closed, ' +
|
||||
`code=${code}, reason=${reason}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info(`Provisioner: socket closed, code=${code}, reason=${reason}`);
|
||||
|
||||
// Is URL from the socket displayed as a QR code?
|
||||
const isActive = index === this.#sockets.length - 1;
|
||||
this.#sockets.splice(index, 1);
|
||||
|
||||
// Graceful closure
|
||||
if (state === SocketState.Done) {
|
||||
log.info('Provisioner: socket closed gracefully');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
log.info('Provisioner: active socket closed');
|
||||
this.#notify({
|
||||
kind:
|
||||
state === SocketState.WaitingForUuid
|
||||
|
||||
Reference in New Issue
Block a user