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
This commit is contained in:
Matheus Filype
2025-09-07 08:10:39 -03:00
committed by GitHub
parent 54a4548c1b
commit d2adbaf3fc
+7 -4
View File
@@ -587,7 +587,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
const willSendMessageAgain = (id: string, participant: string) => {
const key = `${id}:${participant}`
const retryCount = msgRetryCache.get<number>(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) {