From 8c966dfbd802020b11adf96a6e9fc8769b010e80 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Wed, 11 Oct 2023 20:38:03 +0200 Subject: [PATCH] Fix retry logic --- ts/sql/Server.ts | 5 ++++- ts/util/handleRetry.ts | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index 4f106a9b59..e422794e60 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -5728,7 +5728,10 @@ async function removeAllConfiguration( } db.exec( - "UPDATE conversations SET json = json_remove(json, '$.senderKeyInfo');" + ` + UPDATE conversations SET json = json_remove(json, '$.senderKeyInfo'); + UPDATE storyDistributions SET senderKeyInfoJson = NULL; + ` ); })(); } diff --git a/ts/util/handleRetry.ts b/ts/util/handleRetry.ts index 7b27872774..d77825a0b0 100644 --- a/ts/util/handleRetry.ts +++ b/ts/util/handleRetry.ts @@ -46,9 +46,10 @@ const RETRY_LIMIT = 5; // Entrypoints -const retryRecord = new Map(); +type RetryKeyType = `${AciString}.${number}:${number}`; +const retryRecord = new Map(); -export function _getRetryRecord(): Map { +export function _getRetryRecord(): Map { return retryRecord; } @@ -73,8 +74,9 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise { return; } - const retryCount = (retryRecord.get(sentAt) || 0) + 1; - retryRecord.set(sentAt, retryCount); + const retryKey: RetryKeyType = `${requesterAci}.${requesterDevice}:${sentAt}`; + const retryCount = (retryRecord.get(retryKey) || 0) + 1; + retryRecord.set(retryKey, retryCount); if (retryCount > RETRY_LIMIT) { log.warn( `onRetryRequest/${logId}: retryCount is ${retryCount}; returning early.` @@ -232,8 +234,9 @@ export async function onDecryptionError( log.info(`onDecryptionError/${logId}: Starting...`); - const retryCount = (retryRecord.get(timestamp) || 0) + 1; - retryRecord.set(timestamp, retryCount); + const retryKey: RetryKeyType = `${senderAci}.${senderDevice}:${timestamp}`; + const retryCount = (retryRecord.get(retryKey) || 0) + 1; + retryRecord.set(retryKey, retryCount); if (retryCount > RETRY_LIMIT) { log.warn( `onDecryptionError/${logId}: retryCount is ${retryCount}; returning early.`