fix: restrict disable-prefetch feature to Redis brokers only #9919
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.
Description
This pull request restricts the
--disable-prefetchfeature to Redis brokers only to resolve compatibility issues with RabbitMQ and other brokers.Background:
The
--disable-prefetchfeature 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 theqosattribute 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.Channeland lacks theqosattribute, causingAttributeError: 'Channel' object has no attribute 'qos'.Solution:
This PR makes the feature Redis-specific by:
driver_type == 'redis') before applying disable-prefetch logicChanges Made:
celery/worker/consumer/tasks.pyto check broker type and only apply prefetch logic for Rediscelery/bin/worker.pyhelp text to mention Redis-only supportTesting:
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