Skip to content

Check exclusive queue owner before deleting a queue#15276

Merged
michaelklishin merged 3 commits intomainfrom
check-owner-when-deleting-exclusive-queue
Jan 16, 2026
Merged

Check exclusive queue owner before deleting a queue#15276
michaelklishin merged 3 commits intomainfrom
check-owner-when-deleting-exclusive-queue

Conversation

@mkuratczyk
Copy link
Copy Markdown
Contributor

[Why]
For a long time, there has been race condition when deleting exclusive queues - if a connection was re-established and a queue with the same name was declared, we could delete the new queue.

For example, with many MQTT consumers, if we performed a rolling restart of the cluster and the clients reconnected without any delay, after the restart, we sometimes had the expected number of connections but a lower number of queues, even though there should be a queue for each consumer.

[How]
Check that the exclusive_owner has the value we expect when requesting deletion. If the value is different, this means this is effectively a different queue (same name, but a different connection), so we should not delete it.

[Testing]
Here's an example of how to test before/after:

  1. With MQTT QoS0 queue type:
make start-cluster RABBITMQ_ENABLED_PLUGINS="rabbitmq_management,rabbitmq_mqtt"
omq mqtt --uri mqtt://localhost:1883,mqtt://localhost:1884,mqtt://localhost:1885 -x 100 -y 100 -r 1
make restart-cluster RABBITMQ_ENABLED_PLUGINS="rabbitmq_management,rabbitmq_mqtt"
rabbitmqctl -n rabbit-1 list_queues | rg -c mqtt
  1. With classic queues:
make start-cluster RABBITMQ_ENABLED_PLUGINS="rabbitmq_management,rabbitmq_mqtt"
omq mqtt --uri mqtt://localhost:1883,mqtt://localhost:1884,mqtt://localhost:1885 -x 100 -y 100 -r 1 --mqtt-publisher-qos 1 --mqtt-consumer-qos 1
make restart-cluster RABBITMQ_ENABLED_PLUGINS="rabbitmq_management,rabbitmq_mqtt"
rabbitmqctl -n rabbit-1 list_queues | rg -c mqtt

In both cases, you will almost certainly see that once nodes are restarted, the number of published messages doesn't match the number of consumed messages. list_queues will almost certainly return fewer than 100 queues before the PR. With this PR, the number of queues and messages flowing should meet expectations.

@mkuratczyk mkuratczyk force-pushed the check-owner-when-deleting-exclusive-queue branch 2 times, most recently from 82400ab to 876f640 Compare January 16, 2026 11:27
Copy link
Copy Markdown
Collaborator

@dumbbell dumbbell left a comment

Choose a reason for hiding this comment

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

Nice work!

@mkuratczyk mkuratczyk force-pushed the check-owner-when-deleting-exclusive-queue branch from b02bd46 to 876f640 Compare January 16, 2026 13:40
[Why]
For a long time, there has been race condition when deleting
exclusive queues - if a connection was re-established and a queue
with the same name was declared, we could delete the new queue.

For example, with many MQTT consumers, if we performed a rolling restart
of the cluster and the clients reconnected without any delay, after the
restart, we sometimes had the expected number of connections but a lower
number of queues, even though there should be a queue for each consumer.

[How]
Check that the exclusive_owner has the value we expect when requesting
deletion. If the value is different, this means this is effectively a
different queue (same name, but a different connection), so we should
not delete it.
@mkuratczyk mkuratczyk force-pushed the check-owner-when-deleting-exclusive-queue branch from 876f640 to 31ba23a Compare January 16, 2026 14:09
@mkuratczyk mkuratczyk marked this pull request as ready for review January 16, 2026 15:00
@michaelklishin michaelklishin added this to the 4.3.0 milestone Jan 16, 2026
@michaelklishin michaelklishin merged commit ed13c04 into main Jan 16, 2026
576 of 577 checks passed
@michaelklishin michaelklishin deleted the check-owner-when-deleting-exclusive-queue branch January 16, 2026 19:46
mergify bot pushed a commit that referenced this pull request Jan 16, 2026
(cherry picked from commit 8418f61)
mergify bot pushed a commit that referenced this pull request Jan 16, 2026
(cherry picked from commit 49ab811)
michaelklishin added a commit that referenced this pull request Jan 16, 2026
Check exclusive queue owner before deleting a queue (backport #15276)
mergify bot pushed a commit that referenced this pull request Jan 16, 2026
(cherry picked from commit 8418f61)
(cherry picked from commit 5f5b358)
mergify bot pushed a commit that referenced this pull request Jan 16, 2026
(cherry picked from commit 49ab811)
(cherry picked from commit 403c31d)
michaelklishin added a commit that referenced this pull request Jan 17, 2026
Check exclusive queue owner before deleting a queue (backport #15276) (backport #15286)
michaelklishin added a commit that referenced this pull request Feb 24, 2026
michaelklishin added a commit that referenced this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants