Repository navigation
Conversation
comino
force-pushed
the
rabbitmq-lost-wakeup
branch
from
November 12, 2026 16:32
4ffbbde to
87dfbb1
Compare
waitForMessages checks the received queue and starts waiting while holding the consumer mutex, but deliveries notified the condition variable without it. A notify that fell between the check and the wait was lost, so the reader slept until the next delivery or the end of the flush interval. This delays a full block, a direct SELECT, DROP TABLE and shutdown. Notify under the mutex, also in stop(). Without either lock its unit test fails in nearly every run.
comino
force-pushed
the
rabbitmq-lost-wakeup
branch
from
November 12, 2026 23:55
87dfbb1 to
c34bb0e
Compare
comino
marked this pull request as ready for review
November 13, 2026 00:04
Contributor
|
Workflow [PR], commit [c34bb0e] Summary: ✅
AI ReviewSummaryThe PR prevents lost delivery and stop notifications in Missing context / blind spots
Final VerdictStatus: ✅ Approve |
This branch has not been deployed
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a rare race in the
RabbitMQtable engine: the consuming thread could miss the notification about a new message or about the table being stopped, and wait until the next message or the end of the flush interval. This could occasionally delay a block,DROP TABLEand server shutdown by up to one flush interval.Description
A minor fix, found while working on #130767 (RabbitMQ event loop on its own thread) and split out so it can be reviewed on its own. It does not block #130767.
Bug.
RabbitMQConsumer::waitForMessageschecks the queue and starts waiting oncvwhile holdingmutex. The delivery callback andstop()notifiedcvwithout holdingmutex, so a notify could land between the reader's check and its wait and be lost. The reader then sleeps until the next message or its timeout: the flush interval, or 10 minutes (SANITY_TIMEOUT) withrabbitmq_flush_interval_ms = 0. The code is the same in all supported releases. The window is a few instructions wide, so a lost wake-up is rare.Impact. A missed wake-up delays the reader until the next message arrives, at most until the flush interval ends: 7.5 s with the default
stream_flush_interval_ms, 10 minutes withrabbitmq_flush_interval_ms = 0.DROP TABLEand server shutdown wait the same way.sequenceDiagram participant R as Reader (waitForMessages) participant D as Delivery callback / stop() R->>R: lock mutex (h:81), queue is empty (h:85) D->>D: push message (cpp:131) D-->>R: notify without mutex (cpp:135, stop: cpp:41): lost, R is not waiting yet R->>R: wait on condition variable cv (h:84) Note over R: sleeps until the next message<br/>or the flush interval ends (7.5 s by default)Lines in
RabbitMQConsumeron master: h:81-85, cpp:131-135, cpp:38-41.Fix. Notify under
mutexin both places, so a notify can only happen before the reader's check or after its wait has started:sequenceDiagram participant R as Reader (waitForMessages) participant D as Delivery callback / stop() R->>R: lock mutex (h:83), queue is empty (h:87) D->>D: push message (cpp:47), then lock mutex (cpp:51): blocks R->>R: wait on condition variable cv, releases mutex (h:86) D-->>R: notify holding mutex (cpp:52, stop: cpp:66-67) Note over R: wakes up at onceLines in
RabbitMQConsumerin this PR: h:83-87, cpp:45-52, cpp:38-41, cpp:64-67.If the delivery takes the mutex first, the reader's check already sees the message and does not wait.
stop()now calls the existingwakeUp(), which does exactly that. The delivery path moves into a smallpushMessagehelper so that a test can call it. The callback holdschannel_mutexwhile it notifies, somutexis now taken underchannel_mutex;mutexis a leaf lock (only the queue check and atomics run under it), so this adds no lock-order risk.Tests. Two gtests race a helper thread against
waitForMessagesfor 500000 rounds:DeliveryWakesWaitingReaderandStopWakesWaitingReader. TSan build:DeliveryWakesWaitingReaderin 6 of 6 runs (first lost wake-up at round 1 to 7043); reverting thestop()lock failsStopWakesWaitingReaderin 6 of 6 runs (round 3 to 638). With 50000 rounds one of 12 such runs missed it, hence the larger count.pushMessagedoes not exist. A broker-based integration test cannot hit a window this narrow.Workflow [PR]
Sync PR [sync-upstream/pr/130854]