Skip to content

feat: tolerate queue declares that don't match the existing queue (DS-3366) - #81

Merged
nikosd23 merged 4 commits into
masterfrom
feature/DS-3366-tolerant-queue-declares
Oct 13, 2026
Merged

nikosd23 merged 4 commits into
masterfrom
feature/DS-3366-tolerant-queue-declares

Conversation

@ikarachristos

@ikarachristos ikarachristos commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Why

We're converting our queues from classic to quorum before the RabbitMQ 4 upgrade (DS-3366). During a rolling deploy, old and new pods declare the same queue with different arguments (classic vs quorum, with or without priority). RabbitMQ rejects the mismatched declare and closes the channel it ran on.

Today every declare runs on the shared consume channel, so one rejected declare drops every consumer in the service, and orka's reconnect loop hits the same rejection again. Old and new pods keep knocking each other over.

What changes

  • Each queue declare runs on its own short-lived channel.
  • If the queue already exists with different arguments, we log a warning and consume the queue as it is, with its existing arguments.
  • Any other declare error, including invalid arguments for a new queue, still rejects createQueue, but the other consumers stay connected.
  • Server-named queues (empty name) and Queues built on a caller's own channel, such as Migrator's, behave as before.

Released as 5.x (minor), not 6.0: orka depends on rabbit-queue ^5.9.2, and a major version would install a second copy alongside it. Changelog entry added for the other teams on the vhost.

Testing

New integration tests cover an existing queue declared with a different type or priority (both directions), invalid arguments on a new queue, and a non-406 error. Each test checks that messages are still consumed and nothing disconnects. Without this change, the first one fails with the consume connection closed. The full suite passes on RabbitMQ 3.13.7 and 4.2.1.

🤖 Generated with Claude Code

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.

🟡 Changes recommended

Concurrent declarations can exhaust the connection’s negotiated channel limit.

1 open finding
What changed in this PR

Isolates queue declarations so mismatches do not disconnect existing consumers during queue migrations.

Changes:

  • Declares queues on short-lived channels and tolerates existing-queue mismatches.
  • Adds integration coverage for mismatches and declaration errors.
  • Documents tolerant declarations and release behavior.
File Description
ts/​rabbit.ts Associates channels with their connection.
ts/​queue.ts Implements isolated, tolerant declarations.
ts/​channel.ts Adds connection metadata to channels.
test/​rabbit.test.ts Covers mismatch and error scenarios.
test/​queue.test.ts Updates declaration spying.
README.md Documents the new behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ts/queue.ts Outdated

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.

🟡 Changes recommended

The fixed concurrency cap can still exceed the connection’s negotiated channel limit.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

Comment thread ts/queue.ts

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

The implementation matches the stated behavior and includes appropriate failure-path and concurrency coverage.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@ikarachristos
ikarachristos force-pushed the feature/DS-3366-tolerant-queue-declares branch from 0da3da1 to ca68b5e Compare October 13, 2026 06:34
Comment thread ts/queue.ts Outdated
Comment thread ts/queue.ts Outdated
Comment thread ts/queue.ts
ikarachristos and others added 4 commits October 13, 2026 10:11
…-3366)

Declare each queue on a short-lived channel. On a 406 for a queue that
exists with different arguments, log a warning and consume the queue as
it is, instead of closing the shared consume channel and disconnecting
every consumer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Startup declares run concurrently, and each one now opens its own channel,
so a service with many queues could exhaust the connection's channel_max.
Cap declare channels at 10 per connection; further declares wait for a slot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cap of 10 ignored the consume channel already open on the connection,
so a broker with channel_max of 10 or less could still run out of channels.
Derive the cap from the negotiated channelMax, reserving the consume channel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(DS-3366)

Tolerating every 406 hid mismatches the migration doesn't need, such as a
delay queue whose dead-letter routing key changed. Only x-queue-type and
x-max-priority are tolerated now, and only with the new
tolerateQueueTypeMismatch option, which is off by default. The broker
reports one mismatch at a time and checks a quorum queue's type before its
TTL and delivery limit, so after a tolerated mismatch the queue is
redeclared with its current value to let the broker check the rest.

Binds and unbinds also run on short-lived channels, so a failed bind
rejects without closing the consume channel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ikarachristos
ikarachristos force-pushed the feature/DS-3366-tolerant-queue-declares branch from 63a4b12 to fa29561 Compare October 13, 2026 07:11
@nikosd23
nikosd23 merged commit 7ea4b84 into master Oct 13, 2026
8 checks passed
@nikosd23
nikosd23 deleted the feature/DS-3366-tolerant-queue-declares branch October 13, 2026 07:13
ikarachristos added a commit that referenced this pull request Oct 13, 2026
…quorum

Keeps both options next to each other: scheduledPublishQueuesAsQuorum from
this PR and tolerateQueueTypeMismatch from #81. 5.10.0 shipped without this
PR, so its changelog entry moves to 5.11.x.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants