From f688f0069574de789fcc53ffab3b998db16eacdc Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Wed, 25 Feb 2026 20:15:14 -0300 Subject: [PATCH] perf: fix slow message delivery and post-restart connection latency perf: fix slow message delivery and post-restart connection latency --- src/Socket/socket.ts | 8 ++++---- src/Types/Socket.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Socket/socket.ts b/src/Socket/socket.ts index a5f5e1da..e5885108 100644 --- a/src/Socket/socket.ts +++ b/src/Socket/socket.ts @@ -183,7 +183,7 @@ export const makeSocket = (config: SocketConfig) => { // after a pm2 restart because the previous edge server retained stale state. // Signal keys and auth credentials are NOT affected — no QR re-scan is needed. // hadStaleRoutingInfo is used below to skip the offline buffer on reconnect scenarios - // (same channel, new QR scan) so live messages are not held hostage by the backlog buffer. + // (restart of an already-authenticated session) so live messages are not held hostage by the backlog buffer. let hadStaleRoutingInfo = false if (config.clearRoutingInfoOnStart && authState?.creds?.routingInfo) { logger.info('clearRoutingInfoOnStart: discarding stored routingInfo to force fresh edge server assignment') @@ -1615,12 +1615,12 @@ export const makeSocket = (config: SocketConfig) => { // Prometheus / history consolidation) and is typically set to 5-30 s by operators. // This constant must remain short regardless so that a large offline backlog cannot // hold live incoming messages hostage for minutes. - // When clearRoutingInfoOnStart cleared a stale routingInfo, this is a reconnect of an - // existing session (same channel, new QR scan after disconnect). In this case we skip + // When clearRoutingInfoOnStart cleared a stale routingInfo, this is a restart of an + // already-authenticated session (no QR re-scan needed). In this case we skip // the offline buffer entirely so live messages are not held hostage waiting for the // server to finish flushing the pending-message backlog (CB:ib,,offline). // For normal restarts (no stale routingInfo) the standard 5 s safety cap applies. - const OFFLINE_BUFFER_TIMEOUT_MS = hadStaleRoutingInfo ? 0 : 5_000 + const OFFLINE_BUFFER_TIMEOUT_MS = 5_000 let offlineBufferTimeout: NodeJS.Timeout | undefined process.nextTick(() => { diff --git a/src/Types/Socket.ts b/src/Types/Socket.ts index 7804c96b..800f4cba 100644 --- a/src/Types/Socket.ts +++ b/src/Types/Socket.ts @@ -157,7 +157,7 @@ export type SocketConfig = { * Recommended usage: enable this option in your `startSock()` call right after * deploying a new version, then disable it on subsequent reconnections. * - * @default false + * @default true */ clearRoutingInfoOnStart: boolean