Prevent multiple parallel signed prekey rotations
* Prevent multiple parallel signed prekey rotations * When logging error, recalculate id to capture sealed sender info
This commit is contained in:
parent
22f5c01247
commit
0df9b4b8fb
2 changed files with 24 additions and 22 deletions
|
@ -7,7 +7,6 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
const ROTATION_INTERVAL = 48 * 60 * 60 * 1000;
|
const ROTATION_INTERVAL = 48 * 60 * 60 * 1000;
|
||||||
let timeout;
|
let timeout;
|
||||||
let scheduledTime;
|
|
||||||
|
|
||||||
function scheduleNextRotation() {
|
function scheduleNextRotation() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
@ -15,18 +14,23 @@
|
||||||
storage.put('nextSignedKeyRotationTime', nextTime);
|
storage.put('nextSignedKeyRotationTime', nextTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
function run() {
|
function scheduleRotationForNow() {
|
||||||
|
const now = Date.now();
|
||||||
|
storage.put('nextSignedKeyRotationTime', now);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
window.log.info('Rotating signed prekey...');
|
window.log.info('Rotating signed prekey...');
|
||||||
getAccountManager()
|
try {
|
||||||
.rotateSignedPreKey()
|
await getAccountManager().rotateSignedPreKey();
|
||||||
.catch(() => {
|
scheduleNextRotation();
|
||||||
window.log.error(
|
setTimeoutForNextRun();
|
||||||
'rotateSignedPrekey() failed. Trying again in five seconds'
|
} catch (error) {
|
||||||
);
|
window.log.error(
|
||||||
setTimeout(runWhenOnline, 5000);
|
'rotateSignedPrekey() failed. Trying again in five seconds'
|
||||||
});
|
);
|
||||||
scheduleNextRotation();
|
setTimeout(setTimeoutForNextRun, 5000);
|
||||||
setTimeoutForNextRun();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function runWhenOnline() {
|
function runWhenOnline() {
|
||||||
|
@ -38,7 +42,7 @@
|
||||||
);
|
);
|
||||||
const listener = () => {
|
const listener = () => {
|
||||||
window.removeEventListener('online', listener);
|
window.removeEventListener('online', listener);
|
||||||
run();
|
setTimeoutForNextRun();
|
||||||
};
|
};
|
||||||
window.addEventListener('online', listener);
|
window.addEventListener('online', listener);
|
||||||
}
|
}
|
||||||
|
@ -48,14 +52,11 @@
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const time = storage.get('nextSignedKeyRotationTime', now);
|
const time = storage.get('nextSignedKeyRotationTime', now);
|
||||||
|
|
||||||
if (scheduledTime !== time || !timeout) {
|
window.log.info(
|
||||||
window.log.info(
|
'Next signed key rotation scheduled for',
|
||||||
'Next signed key rotation scheduled for',
|
new Date(time).toISOString()
|
||||||
new Date(time).toISOString()
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduledTime = time;
|
|
||||||
let waitTime = time - now;
|
let waitTime = time - now;
|
||||||
if (waitTime < 0) {
|
if (waitTime < 0) {
|
||||||
waitTime = 0;
|
waitTime = 0;
|
||||||
|
@ -75,7 +76,8 @@
|
||||||
initComplete = true;
|
initComplete = true;
|
||||||
|
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
runWhenOnline();
|
scheduleRotationForNow();
|
||||||
|
setTimeoutForNextRun();
|
||||||
} else {
|
} else {
|
||||||
setTimeoutForNextRun();
|
setTimeoutForNextRun();
|
||||||
}
|
}
|
||||||
|
|
|
@ -607,7 +607,7 @@ MessageReceiver.prototype.extend({
|
||||||
return promise.catch(error => {
|
return promise.catch(error => {
|
||||||
window.log.error(
|
window.log.error(
|
||||||
'queueEnvelope error handling envelope',
|
'queueEnvelope error handling envelope',
|
||||||
id,
|
this.getEnvelopeId(envelope),
|
||||||
':',
|
':',
|
||||||
error && error.stack ? error.stack : error
|
error && error.stack ? error.stack : error
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue