From d2adbaf3fc7f4071136b023957ca47ac51d7a791 Mon Sep 17 00:00:00 2001 From: Matheus Filype <67132916+Santosl2@users.noreply.github.com> Date: Sun, 7 Sep 2025 08:10:39 -0300 Subject: [PATCH] fix: message retries loop (#1641) * fix: improve message resend logic by adding checks for message IDs * Revert "fix: improve message resend logic by adding checks for message IDs" This reverts commit c03f9d8e6fc6cbfbb9d1f8f67c169700e704213d. * fix: enhance message resend logic by adding checks for message IDs * fix: adjust message resend logic to allow maximum retry count --- src/Socket/messages-recv.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 7420ad9b..e2a90d2f 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -587,7 +587,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const willSendMessageAgain = (id: string, participant: string) => { const key = `${id}:${participant}` const retryCount = msgRetryCache.get(key) || 0 - return retryCount < maxMsgRetryCount + return retryCount <= maxMsgRetryCount } const updateSendMessageAgainCount = (id: string, participant: string) => { @@ -614,8 +614,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { logger.debug({ participant, sendToAll }, 'forced new session for retry recp') for (const [i, msg] of msgs.entries()) { - if (msg) { - updateSendMessageAgainCount(ids[i]!, participant) + if (!ids[i]) continue + + if (msg && willSendMessageAgain(ids[i], participant)) { + updateSendMessageAgainCount(ids[i], participant) const msgRelayOpts: MessageRelayOptions = { messageId: ids[i] } if (sendToAll) { @@ -703,9 +705,10 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { // correctly set who is asking for the retry key.participant = key.participant || attrs.from const retryNode = getBinaryNodeChild(node, 'retry') - if (willSendMessageAgain(ids[0]!, key.participant!)) { + if (ids[0] && key.participant && willSendMessageAgain(ids[0], key.participant!)) { if (key.fromMe) { try { + updateSendMessageAgainCount(ids[0], key.participant) logger.debug({ attrs, key }, 'recv retry request') await sendMessagesAgain(key, ids, retryNode!) } catch (error: any) {