perf: fix slow message delivery and post-restart connection latency

perf: fix slow message delivery and post-restart connection latency
This commit is contained in:
Renato Alcara
2026-02-25 20:15:14 -03:00
committed by GitHub
parent c39bda3720
commit f688f00695
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -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(() => {