#2810·Baileys

Initial event buffer can be held forever: `<ib><offline>` never arrives and `!!node.attrs.offline` treats `offline="0"` as offline

Author: clebercalejonCreated Sep 8, 2026Updated Sep 23, 2026
LabelsStale

Version

  • @whiskeysockets/[email protected] (npm tarball, read locally).
  • I am aware SECURITY.md declares < 7.0 unsupported. I am reporting it anyway because the two code paths below appear to be unchanged in the published 7.0.0-rc14 tarball (Socket/messages-recv.js:1603 and :1300-1302) — that comparison is from an earlier reading of the published tarball, not of master. I have not checked master. If these were fixed after rc14, please close this and point me at the commit.

Environment

  • Node.js 20, Linux container, single companion (multi-device) socket, long-lived.
  • syncFullHistory: false — the log shows History sync is disabled by config.
  • useMultiFileAuthState + makeCacheableSignalKeyStore, default transactionOpts.
  • Baileys logger at info.

Expected behavior

After CB:success, the initial ev.buffer() opened in Socket/socket.js is eventually released, so messages.upsert reaches application handlers — either because <ib><offline> arrives, or through some fallback.

Observed behavior (production observation, not a lab repro)

Across 10 consecutive connections spanning 8h46m, on the same paired session:

marker before the boundary after the boundary
opened connection to WA 46 10
offline preview received 46 10
handled N offline messages/notifications 46 0
application messages.upsert handler invoked continuously 0
  • The ratio opened connection to WA : handled N offline … was 1:1 without exception for weeks (46:46 on the day the problem started; 17:17 on the previous full day).
  • The socket stays healthy the whole time: connection: 'open', no loggedOut, no Connection Failure. Only the ingestion is dead.
  • offline preview received still arrives on 10 of 10 broken connections, and the client answers it with <ib><offline_batch count="100"/></ib> as the code does. So the offline-batch handshake starts from both sides on every connection — it just never closes.
  • Restarting the process did not help: the state survived two process starts and a full container redeploy.
  • Messages are not lost server-side: the same message ids keep being redelivered on every new connection (40 of 49 distinct ids crossed a container replacement), and each one fails to decrypt and is retried or NACKed. So the server clearly still has the batch — it just never sends <ib><offline>.

(All of the above is observation from our own logs. Everything below is code reading of the published 6.7.24 tarball.)

Code reading — what makes the buffer unrecoverable

(a) Socket/messages-recv.js:879-887 — offline="0" is treated as offline

javascript
const processNode = (type, node, identifier, exec) => {
    const isOffline = !!node.attrs.offline;
    if (isOffline) {
        offlineNodeProcessor.enqueue(type, node);   // serial queue, never calls ev.flush()
    }
    else {
        processNodeWithBuffer(node, identifier, exec);   // this one buffers + flushes
    }
};

node.attrs.offline is a string, so !!"0" === true. A <message offline="0"> — which by its value reads as "nothing pending" — takes the enqueue branch. The serial queue at :847-877 contains no ev.flush() anywhere.

The same string-truthiness appears at :699: upsertMessage(msg, node.attrs.offline ? 'append' : 'notify'), so offline="0" messages are also classified as append rather than notify.

In our capture, every incoming message node carried the attribute: of 84 sampled msgAttrs (logged by messages-recv.js:154 on sent retry receipt), 45 had offline="0", 39 had offline="1", and none were missing it. Before the problem started, 2 of 11 samples had no offline attribute at all.

(b) Socket/socket.js:536-556 — the initial buffer has exactly two exits, and both can close

javascript
let didStartBuffer = false;
process.nextTick(() => {
    if (creds.me?.id) { ev.buffer(); didStartBuffer = true; }
    ev.emit('connection.update', { connection: 'connecting', receivedPendingNotifications: false, qr: undefined });
});

ws.on('CB:ib,,offline', (node) => {
    const child = getBinaryNodeChild(node, 'offline');
    const offlineNotifs = +(child?.attrs.count || 0);
    logger.info(`handled ${offlineNotifs} offline messages/notifications`);
    if (didStartBuffer) { ev.flush(); logger.trace('flushed events for initial buffer'); }
    ev.emit('connection.update', { receivedPendingNotifications: true });
});

grep -rn 'flush(' lib/ finds six call sites, but four of them (Socket/chats.js:795, :805, :875, :886) are downstream of this handler: they require connection.update { receivedPendingNotifications: true } or a syncState that only this handler can produce (and :886 is only armed when willSyncHistory === true, which is false for us).

That leaves two real exits:

  1. Socket/socket.js:552 — requires <ib><offline> to arrive.
  2. Socket/messages-recv.js:842 (processNodeWithBuffer) — requires a message node without the offline attribute, i.e. the else branch of (a).

If the server stops sending <ib><offline> and every message node carries offline, both exits are closed simultaneously and the buffer is held for the entire life of the socket. There is no timeout and no warning — Utils/event-buffer.js has no timer in 6.7.24, isBuffering is a plain boolean, and nothing logs the fact that events are accumulating. The application sees a perfectly healthy connection and zero messages. In our case that lasted 8h46m and only ended because a human looked.

(c) Socket/socket.js:520-527 — the preview node is discarded from the log

javascript
ws.on('CB:ib,,offline_preview', (node) => {
    logger.info('offline preview received', JSON.stringify(node));
    sendNode({ tag: 'ib', attrs: {}, content: [{ tag: 'offline_batch', attrs: { count: '100' } }] });
});

pino's signature here is info(msg, ...interpolationValues); with no %s/%j placeholder in the message, the second argument is dropped. All 51 offline preview received lines in our logs are literally {"level":"info", ..., "msg":"offline preview received"} with no node content. That node is presumably where the server states how many items are pending — exactly the diagnostic needed when the batch never closes — and it is unreadable at any level below trace (which dumps the full XML of every message and is not an option for us on privacy grounds). Passing the node as the first argument (logger.info({ node }, 'offline preview received')) would fix this at zero cost.

(d) Socket/messages-recv.js:649-655 — Key used already or never filled is NACKed with no retry

javascript
await decrypt();
if (msg.messageStubType === proto.WebMessageInfo.StubType.CIPHERTEXT) {
    if (msg?.messageStubParameters?.[0] === MISSING_KEYS_ERROR_TEXT) {
        return sendMessageAck(node, NACK_REASONS.ParsingError);   // 487, and returns
    }
    retryMutex.mutex(async () => { /* ... sendRetryRequest ... */ });
}

MISSING_KEYS_ERROR_TEXT is 'Key used already or never filled' (Utils/decode-wa-message.js:6) and NACK_REASONS.ParsingError is 487 (:7-21). Upstream, that string is a MessageCounterError thrown by libsignal at session_cipher.js:236 when the message key for that counter is not present in the chain of an existing session.

I am not claiming this is wrong — the comment in libsignal says the usual cause is a duplicate delivery. I am flagging it because it interacts with (b): when a client is stuck in the state above, this branch is the one that stops asking the server to resend. Over one of our windows, failed to decrypt message grew from 104 to 128 while sent retry receipt stayed frozen at 84 — every new failure took the 487 branch. I do not know whether a 487 makes the server consider the item delivered. That is part of the question below.

Steps to reproduce

I cannot offer a deterministic repro, and I would rather say so than invent one. What preceded it, exactly once in weeks of uptime:

  1. Long-lived companion socket, ingesting normally (opened : handled = 1:1 for 46 consecutive connections).
  2. The host machine suspends. Roughly 2h49m with no socket open at all — ten consecutive reconnect failures, backoff pinned at its 60 s ceiling.
  3. The host wakes. The first connection after the wake already shows the symptom: preview arrives, <ib><offline> never does, buffer never flushes. Every subsequent connection behaves identically.

Update — what finally cleared it. After 8h46m we unlinked the companion device from the phone (server sent <stream:error code="401"><conflict type="device_removed"/>), discarded the session directory and paired again. The first connection of the new session received <ib><offline> immediately (handled 0 offline messages/notifications), messages.upsert reached the application within one second, and the ratio has been 1:1 since. Two process restarts and a full container redeploy on the old session had changed nothing. So whatever holds the batch open is bound to the linked device's server-side session, not to the client process — which is also why I could not find a client-side way out.

Questions

  1. Is it ever expected for a client to receive <ib><offline_preview>, answer it with <ib><offline_batch count="…"/>, and then never receive <ib><offline>? If yes, what is the client supposed to do about it?
  2. Should the initial ev.buffer() have a timeout? Right now a missing server node translates into permanent, silent, total loss of message delivery to the application, with a connection that reports itself as healthy. Even a logger.warn after N seconds would turn a silent failure into a visible one.
  3. Is const isOffline = !!node.attrs.offline intended to treat offline="0" as offline? If the attribute is meant as a boolean-ish flag, node.attrs.offline === '1' (or a numeric parse) would seem closer to the intent, and it would keep the second flush path reachable.
  4. Does a <ack error="487"> cause the server to consider an offline item delivered and drop it from the pending batch? This decides whether a client stuck in this state is merely blind or is actively losing the queue.

The stuck session is gone now, so I can no longer run live diagnostics against it; I do have the full client logs of the 8h46m window (masked) and can share excerpts on request.