Skip to content

Conversation

@Dkhodos
Copy link
Contributor

@Dkhodos Dkhodos commented Sep 29, 2025

Description

This pull request restricts the --disable-prefetch feature to Redis brokers only to resolve compatibility issues with RabbitMQ and other brokers.

Background:
The --disable-prefetch feature was introduced in PR #9863 to allow workers to only fetch tasks when process slots are available, preventing task hoarding and improving fair distribution. However, as reported in issue #9913, this feature causes crashes when used with RabbitMQ brokers due to differences in channel implementation - RabbitMQ channels don't have the qos attribute that the feature relies on.

Root Cause:
The original implementation assumed all broker channels would have the same interface as Redis channels, but RabbitMQ's Kombu channel implementation doesn't extend virtual.Channel and lacks the qos attribute, causing AttributeError: 'Channel' object has no attribute 'qos'.

Solution:
This PR makes the feature Redis-specific by:

  • Adding broker transport detection (driver_type == 'redis') before applying disable-prefetch logic
  • Logging a warning when the feature is used with non-Redis brokers
  • Gracefully ignoring the setting for incompatible brokers
  • Updating documentation and CLI help to reflect the Redis-only limitation

Changes Made:

  • Code: Modified celery/worker/consumer/tasks.py to check broker type and only apply prefetch logic for Redis
  • CLI: Updated celery/bin/worker.py help text to mention Redis-only support
  • Documentation: Updated configuration docs, FAQ, and optimization guide to note Redis limitation
  • Tests: Added comprehensive tests for both Redis and non-Redis broker behavior

Testing:

  • All existing disable-prefetch tests pass with Redis broker mocking
  • New tests verify the feature is properly ignored for non-Redis brokers
  • No functionality changes for Redis users - the feature works exactly as before

This is a surgical fix that maintains backward compatibility while preventing crashes on unsupported brokers. Redis users continue to benefit from the feature, while RabbitMQ and other broker users get clear messaging about the limitation instead of cryptic errors.

Fixes #9913

The disable-prefetch feature was originally implemented for all brokers,
but users reported compatibility issues with RabbitMQ. This change
restricts the feature to Redis brokers only, which is where most
testing was conducted.

Changes:
- Add broker transport detection in Tasks.start()
- Only apply disable-prefetch logic for Redis brokers
- Log warning for non-Redis brokers when setting is enabled
- Update CLI help text to mention Redis-only support
- Update documentation to reflect Redis-only limitation
- Add tests for non-Redis broker behavior

Fixes compatibility issues with RabbitMQ and other non-Redis brokers
while maintaining the feature for Redis users.
- Break long line in worker.py help text
- Remove trailing whitespace in test file
…test

The test_log_when_qos_is_false test was failing because our new warning
for non-Redis brokers was being logged, causing the test to expect 2 log
records instead of 1. Fixed by explicitly setting worker_disable_prefetch
to False in this test.
@codecov
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.67%. Comparing base (e7a9550) to head (1835333).
⚠️ Report is 66 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9919      +/-   ##
==========================================
- Coverage   78.67%   78.67%   -0.01%     
==========================================
  Files         153      153              
  Lines       19295    19299       +4     
  Branches     2569     2570       +1     
==========================================
+ Hits        15181    15184       +3     
  Misses       3816     3816              
- Partials      298      299       +1     
Flag Coverage Δ
unittests 78.65% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@auvipy auvipy self-requested a review September 30, 2025 04:12
@auvipy auvipy added this to the 5.6.0 milestone Sep 30, 2025
@auvipy auvipy merged commit 8063230 into celery:main Sep 30, 2025
108 of 109 checks passed
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.

New --disable-prefetch worker option doesn't work with RabbitMQ broker

2 participants