From 1408499d7ceb1607f04ac671fdf5032e0302c35d Mon Sep 17 00:00:00 2001 From: YonkoSam <161728760+YonkoSam@users.noreply.github.com> Date: Sun, 18 Jan 2026 00:11:10 +0100 Subject: [PATCH] moved retryCount before validating the session (#2167) --- src/Socket/messages-recv.ts | 10 +++++----- src/Utils/message-retry-manager.ts | 7 +------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 9363d2b4..e5d8161f 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -431,12 +431,12 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { let shouldRecreateSession = false let recreateReason = '' - if (enableAutoSessionRecreation && messageRetryManager) { + if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) { try { // Check if we have a session with this JID const sessionId = signalRepository.jidToSignalProtocolAddress(fromJid) const hasSession = await signalRepository.validateSession(fromJid) - const result = messageRetryManager.shouldRecreateSession(fromJid, retryCount, hasSession.exists) + const result = messageRetryManager.shouldRecreateSession(fromJid, hasSession.exists) shouldRecreateSession = result.recreate recreateReason = result.reason @@ -989,12 +989,12 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { let shouldRecreateSession = false let recreateReason = '' - if (enableAutoSessionRecreation && messageRetryManager) { + if (enableAutoSessionRecreation && messageRetryManager && retryCount > 1) { try { const sessionId = signalRepository.jidToSignalProtocolAddress(participant) const hasSession = await signalRepository.validateSession(participant) - const result = messageRetryManager.shouldRecreateSession(participant, retryCount, hasSession.exists) + const result = messageRetryManager.shouldRecreateSession(participant, hasSession.exists) shouldRecreateSession = result.recreate recreateReason = result.reason @@ -1179,7 +1179,7 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { const encNode = getBinaryNodeChild(node, 'enc') // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption - if (encNode && encNode.attrs.type === 'msmsg') { + if (encNode?.attrs.type === 'msmsg') { logger.debug({ key: node.attrs.key }, 'ignored msmsg') await sendMessageAck(node, NACK_REASONS.MissingMessageSecret) return diff --git a/src/Utils/message-retry-manager.ts b/src/Utils/message-retry-manager.ts index 76833dda..48be547e 100644 --- a/src/Utils/message-retry-manager.ts +++ b/src/Utils/message-retry-manager.ts @@ -109,7 +109,7 @@ export class MessageRetryManager { /** * Check if a session should be recreated based on retry count and history */ - shouldRecreateSession(jid: string, retryCount: number, hasSession: boolean): { reason: string; recreate: boolean } { + shouldRecreateSession(jid: string, hasSession: boolean): { reason: string; recreate: boolean } { // If we don't have a session, always recreate if (!hasSession) { this.sessionRecreateHistory.set(jid, Date.now()) @@ -120,11 +120,6 @@ export class MessageRetryManager { } } - // Only consider recreation if retry count > 1 - if (retryCount < 2) { - return { reason: '', recreate: false } - } - const now = Date.now() const prevTime = this.sessionRecreateHistory.get(jid)