Fix shutdown race condition to avoid double processing and unnecessary dead-set publishes#288
Merged
Vruttant1403 merged 2 commits intoJun 16, 2026
Conversation
vsr625
force-pushed
the
fix/rabbitmq-shutdown-drain-in-flight-messages
branch
from
June 5, 2026 05:44
4b123a6 to
baa43d9
Compare
vsr625
marked this pull request as ready for review
June 5, 2026 05:52
…ssing During shutdown, consumer connections could be torn down while messages were still being processed, leaving those messages unacked. RabbitMQ then redelivered them, causing the same messages to be processed again after restart. Track in-flight messages with a counter (incremented before processing and decremented in a finally block) and, when stopping the consumers, wait for the in-flight handlers to finish after cancelling subscriptions but before the connection is closed. The wait is bounded by a configurable drain timeout ([:shutdown :drain-timeout-ms], default 5000ms). Also fix the JVM shutdown hook to run (stop ...) and (shutdown-agents) sequentially via do; previously it invoked the result of stop as a function. Adds tests covering in-flight tracking, wait-for-in-flight-messages (including the configured-timeout path), and the drain step in the consumers :stop lifecycle. Co-authored-by: Cursor <[email protected]>
Vruttant1403
force-pushed
the
fix/rabbitmq-shutdown-drain-in-flight-messages
branch
from
June 16, 2026 07:09
21c718e to
59ae2ee
Compare
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.
During shutdown, consumer connections could be torn down while messages were
still being processed, leaving those messages unacked. RabbitMQ then redelivered
them, causing the same messages to be processed again after restart.
Track in-flight messages with a counter (incremented before processing and
decremented in a finally block) and, when stopping the consumers, wait for the
in-flight handlers to finish after cancelling subscriptions but before the
connection is closed. The wait is bounded by a configurable drain timeout
([:shutdown :drain-timeout-ms], default 5000ms).
Also fix the JVM shutdown hook to run (stop ...) and (shutdown-agents)
sequentially via do; previously it invoked the result of stop as a function.
Adds tests covering in-flight tracking, wait-for-in-flight-messages (including
the configured-timeout path), and the drain step in the consumers :stop lifecycle.