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:
Scott Nonnenberg 2019-07-03 11:56:49 -07:00 committed by Ken Powers
parent 22f5c01247
commit 0df9b4b8fb
2 changed files with 24 additions and 22 deletions

View file

@ -7,7 +7,6 @@
window.Whisper = window.Whisper || {};
const ROTATION_INTERVAL = 48 * 60 * 60 * 1000;
let timeout;
let scheduledTime;
function scheduleNextRotation() {
const now = Date.now();
@ -15,18 +14,23 @@
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...');
getAccountManager()
.rotateSignedPreKey()
.catch(() => {
window.log.error(
'rotateSignedPrekey() failed. Trying again in five seconds'
);
setTimeout(runWhenOnline, 5000);
});
scheduleNextRotation();
setTimeoutForNextRun();
try {
await getAccountManager().rotateSignedPreKey();
scheduleNextRotation();
setTimeoutForNextRun();
} catch (error) {
window.log.error(
'rotateSignedPrekey() failed. Trying again in five seconds'
);
setTimeout(setTimeoutForNextRun, 5000);
}
}
function runWhenOnline() {
@ -38,7 +42,7 @@
);
const listener = () => {
window.removeEventListener('online', listener);
run();
setTimeoutForNextRun();
};
window.addEventListener('online', listener);
}
@ -48,14 +52,11 @@
const now = Date.now();
const time = storage.get('nextSignedKeyRotationTime', now);
if (scheduledTime !== time || !timeout) {
window.log.info(
'Next signed key rotation scheduled for',
new Date(time).toISOString()
);
}
window.log.info(
'Next signed key rotation scheduled for',
new Date(time).toISOString()
);
scheduledTime = time;
let waitTime = time - now;
if (waitTime < 0) {
waitTime = 0;
@ -75,7 +76,8 @@
initComplete = true;
if (newVersion) {
runWhenOnline();
scheduleRotationForNow();
setTimeoutForNextRun();
} else {
setTimeoutForNextRun();
}

View file

@ -607,7 +607,7 @@ MessageReceiver.prototype.extend({
return promise.catch(error => {
window.log.error(
'queueEnvelope error handling envelope',
id,
this.getEnvelopeId(envelope),
':',
error && error.stack ? error.stack : error
);