Skip to content

fix: don't ack a message from before a reconnect on the new channel (DS-3721) - #98

Open
ikarachristos wants to merge 1 commit into
masterfrom
fix/DS-3721-ack-on-delivering-channel
Open

ikarachristos wants to merge 1 commit into
masterfrom
fix/DS-3721-ack-on-delivering-channel

Conversation

@ikarachristos

@ikarachristos ikarachristos commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Jira: DS-3721

Problem

Since 5.13.0 a reconnect moves every queue to the new consume channel (Queue.rebind). The ack handed to a handler read this.channel when it was called, not when the message was delivered. So a handler that was still running when the connection dropped, and finished after the reconnect, acked on the new channel with a delivery tag from the old one.

Delivery tags count per channel, so one of two things happened:

  • The tag belonged to another unacked message on the new channel, which was settled while its own handler was still running.
  • The tag was unknown there, and the broker closed the channel with PRECONDITION_FAILED - unknown delivery tag. That disconnects the service again and requeues everything in flight.

On 5.12.0 the queue kept its old channel, so the same ack failed locally.

Change

onMessage remembers the channel that delivered the message. The ack is skipped, with a warning, once the queue has moved to another channel: the broker requeued the message when its channel closed, so there is nothing left to ack.

The README changelog has an entry under v5.13.x. It says v5.13.1; adjust if the release gets another number. No version bump in this PR.

Tested

Two new tests against a real broker. Both fail on master and pass with the change:

  • Two messages held across a reconnect, the redelivered copies acked, then an ack from before the reconnect. On master the broker closes the channel: PRECONDITION_FAILED - unknown delivery tag 2.
  • One message held across a reconnect. On master the first run's ack settles the redelivered copy.

The full suite passes on RabbitMQ 4.1.2 and 3.13.7 (161 tests).

Not changed

  • An ack on a channel that has closed but has not been replaced yet still throws, as it always has. That includes the confirm callback of a reply that was pending when the channel closed.
  • A run from before the reconnect still publishes its RPC reply on the new channel; only its ack is skipped. The redelivered run replies too.
  • Handlers are not told that their message was requeued. maestro works that out for itself in Workable/maestro#1242.

🤖 Generated with Claude Code

…DS-3721)

Since 5.13.0 a reconnect moves every queue to the new consume channel, and
the ack handed to a handler used whatever channel the queue had when it was
called. A handler still running across the reconnect therefore acked on the
new channel with a delivery tag from the old one. Tags count per channel, so
that settled another message or made the broker close the channel with
"PRECONDITION_FAILED - unknown delivery tag".

onMessage now remembers the channel that delivered the message and skips the
ack, with a warning, once the queue has moved to another one. The broker
requeued the message when its channel closed.

Not changed: an ack on a channel that closed but has not been replaced yet
still throws, as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ikarachristos ikarachristos changed the title Don't ack a message from before a reconnect on the new channel fix: don't ack a message from before a reconnect on the new channel (DS-3721) Nov 19, 2026
@ikarachristos
ikarachristos requested review from nikosd23 and a balanced review from Copilot November 19, 2026 08:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the fix preventing stale acknowledgments after reconnects.

No open issues 🎉

What changed in this PR

This PR fixes acknowledgments from handlers that finish after a reconnect, preventing stale delivery tags from settling unrelated messages or closing the new consume channel.

Changes:

  • Capture the delivery-time channel and skip acknowledgments with a warning when that channel has been replaced.
  • Add two broker-backed regression tests covering unknown delivery tags and accidental acknowledgment of redelivered messages.
  • Document the fix in the v5.13.x changelog.
File Description
ts/​queue.ts Guard acknowledgments against channel replacement after reconnect.
test/​rabbit.test.ts Test both stale-ack failure scenarios across reconnects.
README.md Add a v5.13.1 changelog entry explaining the fix.

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants