Fix retry logic

This commit is contained in:
Fedor Indutny 2023-10-11 20:38:03 +02:00 committed by GitHub
parent e124730cb0
commit 8c966dfbd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View file

@ -5728,7 +5728,10 @@ async function removeAllConfiguration(
} }
db.exec( db.exec(
"UPDATE conversations SET json = json_remove(json, '$.senderKeyInfo');" `
UPDATE conversations SET json = json_remove(json, '$.senderKeyInfo');
UPDATE storyDistributions SET senderKeyInfoJson = NULL;
`
); );
})(); })();
} }

View file

@ -46,9 +46,10 @@ const RETRY_LIMIT = 5;
// Entrypoints // Entrypoints
const retryRecord = new Map<number, number>(); type RetryKeyType = `${AciString}.${number}:${number}`;
const retryRecord = new Map<RetryKeyType, number>();
export function _getRetryRecord(): Map<number, number> { export function _getRetryRecord(): Map<string, number> {
return retryRecord; return retryRecord;
} }
@ -73,8 +74,9 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
return; return;
} }
const retryCount = (retryRecord.get(sentAt) || 0) + 1; const retryKey: RetryKeyType = `${requesterAci}.${requesterDevice}:${sentAt}`;
retryRecord.set(sentAt, retryCount); const retryCount = (retryRecord.get(retryKey) || 0) + 1;
retryRecord.set(retryKey, retryCount);
if (retryCount > RETRY_LIMIT) { if (retryCount > RETRY_LIMIT) {
log.warn( log.warn(
`onRetryRequest/${logId}: retryCount is ${retryCount}; returning early.` `onRetryRequest/${logId}: retryCount is ${retryCount}; returning early.`
@ -232,8 +234,9 @@ export async function onDecryptionError(
log.info(`onDecryptionError/${logId}: Starting...`); log.info(`onDecryptionError/${logId}: Starting...`);
const retryCount = (retryRecord.get(timestamp) || 0) + 1; const retryKey: RetryKeyType = `${senderAci}.${senderDevice}:${timestamp}`;
retryRecord.set(timestamp, retryCount); const retryCount = (retryRecord.get(retryKey) || 0) + 1;
retryRecord.set(retryKey, retryCount);
if (retryCount > RETRY_LIMIT) { if (retryCount > RETRY_LIMIT) {
log.warn( log.warn(
`onDecryptionError/${logId}: retryCount is ${retryCount}; returning early.` `onDecryptionError/${logId}: retryCount is ${retryCount}; returning early.`