Skip to content

Fix RabbitMQ 4.x crash: global QoS not supported on classic queues#2481

Open
Azd325 wants to merge 3 commits intocelery:mainfrom
Azd325:main
Open

Fix RabbitMQ 4.x crash: global QoS not supported on classic queues#2481
Azd325 wants to merge 3 commits intocelery:mainfrom
Azd325:main

Conversation

@Azd325
Copy link

@Azd325 Azd325 commented Mar 6, 2026

RabbitMQ 4.0 removed support for global QoS prefetch (basic.qos with global=true) on classic queues. When Kombu connected to a RabbitMQ 4.x broker, qos_semantics_matches_spec returned False (because the version was not < 3.3), causing Celery to set global=True in its QoS call, which RabbitMQ 4.x immediately rejected with:

540 NOT_IMPLEMENTED - queue does not support global qos

This crashed workers on startup before they could consume any tasks.

Fix the version boundary check in both pyamqp and librabbitmq transports to return True (per-channel QoS) for RabbitMQ >= 4.0:

Before: version < (3, 3)
After: version < (3, 3) or version >= (4, 0)

This restores the correct behavior:

  • RabbitMQ < 3.3: True (spec-compliant per-channel QoS)
  • RabbitMQ 3.3–3.x: False (global QoS semantics)
  • RabbitMQ 4.0+: True (global QoS removed, per-channel only)

RabbitMQ deprecation announcement (2021):
https://www.rabbitmq.com/blog/2021/08/21/4.0-deprecation-announcements

RabbitMQ 4.x classic queues docs (global QoS removal):
https://www.rabbitmq.com/docs/classic-queues

Closes: #2469

RabbitMQ 4.0 removed support for global QoS prefetch (`basic.qos`
with `global=true`) on classic queues. When Kombu connected to a
RabbitMQ 4.x broker, `qos_semantics_matches_spec` returned `False`
(because the version was not < 3.3), causing Celery to set
`global=True` in its QoS call, which RabbitMQ 4.x immediately
rejected with:

  540 NOT_IMPLEMENTED - queue does not support global qos

This crashed workers on startup before they could consume any tasks.

Fix the version boundary check in both `pyamqp` and `librabbitmq`
transports to return `True` (per-channel QoS) for RabbitMQ >= 4.0:

  Before: version < (3, 3)
  After:  version < (3, 3) or version >= (4, 0)

This restores the correct behavior:
  - RabbitMQ < 3.3:   True  (spec-compliant per-channel QoS)
  - RabbitMQ 3.3–3.x: False (global QoS semantics)
  - RabbitMQ 4.0+:    True  (global QoS removed, per-channel only)

RabbitMQ deprecation announcement (2021):
  https://www.rabbitmq.com/blog/2021/08/21/4.0-deprecation-announcements

RabbitMQ 4.x classic queues docs (global QoS removal):
  https://www.rabbitmq.com/docs/classic-queues

Closes: celery#2469
@auvipy auvipy requested a review from Copilot March 7, 2026 11:44
@auvipy auvipy added this to the 5.7.0 milestone Mar 7, 2026
@auvipy auvipy self-requested a review March 7, 2026 11:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a startup crash when Kombu connects to a RabbitMQ 4.x broker using the pyamqp or librabbitmq transports. RabbitMQ 4.0 removed support for global QoS prefetch on classic queues, but the old version boundary check (version < (3, 3)) returned False for all RabbitMQ ≥ 3.3, causing Celery to set global=True in its QoS call — which RabbitMQ 4.x rejects with a 540 NOT_IMPLEMENTED error.

Changes:

  • Fix the version boundary in pyamqp.Transport.qos_semantics_matches_spec to return True for RabbitMQ ≥ 4.0.
  • Apply the same fix symmetrically to librabbitmq.Transport.qos_semantics_matches_spec, and add safe handling for a missing version key in both transports.
  • Add comprehensive unit tests for both transports covering all version boundary cases and the missing-version edge case.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
kombu/transport/pyamqp.py Core fix: adds RabbitMQ 4.0+ condition and safe version key handling
kombu/transport/librabbitmq.py Same fix applied symmetrically to the librabbitmq transport
t/unit/transport/test_pyamqp.py New tests for all QoS version boundary cases in pyamqp
t/unit/transport/test_librabbitmq.py New tests for all QoS version boundary cases in librabbitmq, including the AttributeError path

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.24%. Comparing base (6cc2228) to head (3a99f4f).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
kombu/transport/librabbitmq.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2481      +/-   ##
==========================================
+ Coverage   82.23%   82.24%   +0.01%     
==========================================
  Files          79       79              
  Lines       10080    10088       +8     
  Branches     1150     1152       +2     
==========================================
+ Hits         8289     8297       +8     
  Misses       1589     1589              
  Partials      202      202              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

we should keep support for both old and new versions for easier migrations

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

also can you improve test coverage?

@auvipy
Copy link
Member

auvipy commented Mar 11, 2026

@ChickenBenny

@ChickenBenny
Copy link
Contributor

LGTM! 🚀

@auvipy
Copy link
Member

auvipy commented Mar 12, 2026

the codecov is showing very low coverage

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.

Workers crash on startup with RabbitMQ 4.x — "540 NOT_IMPLEMENTED - queue does not support global qos"

4 participants