Repository navigation
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
Open
ikarachristos wants to merge 1 commit into
ikarachristos wants to merge 1 commit into
Conversation
…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
requested review from
nikosd23
and
a balanced review from Copilot
November 19, 2026 08:17
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 readthis.channelwhen 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:
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
onMessageremembers 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:
PRECONDITION_FAILED - unknown delivery tag 2.The full suite passes on RabbitMQ 4.1.2 and 3.13.7 (161 tests).
Not changed
🤖 Generated with Claude Code