diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 970f511c..029a81fb 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -2695,7 +2695,20 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } }) } catch (error) { - logger.error({ error, node: binaryNodeToString(node) }, 'error in handling message') + // Slim log: identify the message that crashed without dumping the full + // stanza XML (which contains kilobytes of inline ciphertext). Under heavy + // load — e.g. a downstream consumer that throws on every Bad MAC — the + // full XML dumps overwhelm stdout and stall the event loop. Operators + // can still pivot on msgId / from / type; full payload at debug level. + const slimNode = { + tag: node.tag, + id: node.attrs?.id, + from: node.attrs?.from, + type: node.attrs?.type, + participant: node.attrs?.participant + } + logger.error({ error, node: slimNode }, 'error in handling message') + logger.debug({ node: binaryNodeToString(node) }, 'error in handling message — full stanza') } } diff --git a/src/Utils/auth-utils.ts b/src/Utils/auth-utils.ts index adabf548..203dbefc 100644 --- a/src/Utils/auth-utils.ts +++ b/src/Utils/auth-utils.ts @@ -341,14 +341,16 @@ export const addTransactionCapability = ( return result } catch (error) { - // SessionError is part of the normal Bad MAC recovery flow - // (retry receipt → sender resends as pkmsg → new session within ~1.3s). - // Logging it as ERROR creates 2 noise lines per recoverable Bad MAC cycle. - // Downgrade to debug for SessionError; keep ERROR for everything else. - // The error is still re-thrown — recovery behavior is unchanged. + // SessionError / MessageCounterError are part of the normal Bad MAC + // recovery flow (retry receipt → sender resends as pkmsg → new session + // within ~1.3s). Logging them as ERROR creates 2 noise lines per + // recoverable cycle, and under WhatsApp's LID/DSM rollout these fire + // in dense bursts that saturate stdout (synchronous pm2 writes block + // the event loop). Downgrade to debug for both; keep ERROR for + // everything else. The error is still re-thrown — recovery is unchanged. const errName = (error as { name?: string })?.name - if (errName === 'SessionError') { - logger.debug({ error }, 'transaction failed (SessionError — recoverable via retry receipt)') + if (errName === 'SessionError' || errName === 'MessageCounterError') { + logger.debug({ error }, `transaction failed (${errName} — recoverable via retry receipt)`) } else { logger.error({ error }, 'transaction failed, rolling back') }