Repository navigation
Milestone
Description
Checklist
- I have verified that the issue exists against the
mainbranch of Celery. - This has already been asked to the discussions forum first.
- I have read the relevant section in the
contribution guide
on reporting bugs. - I have checked the issues list
for similar or identical bug reports. - I have checked the pull requests list
for existing proposed fixes. - I have checked the commit log
to find out if the bug was already fixed in the main branch. - I have included all related issues and possible duplicate issues
in this issue (If there are none, check this box anyway). - [ I have tried to reproduce the issue with pytest-celery and added the reproduction script below.
Mandatory Debugging Information
- I have included the output of
celery -A proj reportin the issue.
(if you are not able to do this, then at least specify the Celery
version affected). - I have verified that the issue exists against the
mainbranch of Celery. - I have included the contents of
pip freezein the issue. - I have included all the versions of all the external dependencies required
to reproduce this bug.
Optional Debugging Information
- I have tried reproducing the issue on more than one Python version
and/or implementation. - I have tried reproducing the issue on more than one message broker and/or
result backend. - I have tried reproducing the issue on more than one version of the message
broker and/or result backend. - I have tried reproducing the issue on more than one operating system.
- I have tried reproducing the issue on more than one workers pool.
- I have tried reproducing the issue with autoscaling, retries,
ETA/Countdown & rate limits disabled. - I have tried reproducing the issue after downgrading
and/or upgrading Celery and its dependencies.
Related Issues and Possible Duplicates
Related Issues
- None
Possible Duplicates
- None
Environment & Settings
Celery version:
celery report Output:
software -> celery:5.5.0rc4 (immunity) kombu:5.5.0rc2 py:3.12.5
billiard:4.2.1 py-amqp:5.3.1
platform -> system:Linux arch:64bit, ELF
kernel version:6.8.0-51-generic imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:amqp results:disabled
broker_channel_error_retry: True
broker_connection_max_retries: None
broker_connection_retry_on_startup: True
task_acks_late: True
task_default_queue_type: 'quorum'
worker_enable_prefetch_count_reduction: False
broker_url: 'amqp://guest:********@localhost:5672//'
include: ['src.tasks']
deprecated_settings: None
Steps to Reproduce
Required Dependencies
- Minimal Python Version: N/A or Unknown
- Minimal Celery Version: N/A or Unknown
- Minimal Kombu Version: N/A or Unknown
- Minimal Broker Version: N/A or Unknown
- Minimal Result Backend Version: N/A or Unknown
- Minimal OS and/or Kernel Version: N/A or Unknown
- Minimal Broker Client Version: N/A or Unknown
- Minimal Result Backend Client Version: N/A or Unknown
Python Packages
pip freeze Output:
amqp==5.3.1
autopep8==2.3.2
billiard==4.2.1
cached-property==2.0.1
celery==5.5.0rc4
certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.8
click-didyoumean==0.3.1
click-plugins==1.1.1
click-repl==0.3.0
coverage==7.6.10
dnspython==2.6.1
flake8==7.1.1
flower==2.0.1
greenlet==3.1.1
humanize==4.11.0
idna==3.10
inflection==0.5.1
iniconfig==2.0.0
kombu==5.5.0rc2
mccabe==0.7.0
mock==5.1.0
mypy-extensions==1.0.0
packaging==24.2
pika==0.13.0
pluggy==1.5.0
prometheus_client==0.21.1
prompt_toolkit==3.0.48
PyAMQP==0.1.0.7
pycodestyle==2.12.1
pyflakes==3.2.0
pytest==8.3.4
python-dateutil==2.9.0.post0
python-nmap==0.7.1
pytz==2024.2
requests==2.32.3
six==1.17.0
SQLAlchemy==2.0.37
sqlalchemy-orm==1.2.10
Subfind3r==1.3
tornado==6.4.2
typing-inspect==0.9.0
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.2.3
vine==5.1.0
wcwidth==0.2.13
Other Dependencies
Details
Nmap 7.94SVN
Minimally Reproducible Test Case
Details
celery_config.py:
task_acks_late = True
broker_connection_retry_on_startup = True
broker_channel_error_retry = True
broker_connection_max_retries = Nonecelery.py
from celery import Celery
from src.quorum import setup_app_quorum
app = Celery('src',
broker='amqp://guest@localhost//',
include=['src.tasks'])
app.config_from_object('celery_config')
setup_app_quorum(app, ['queue'])quorum.py
from celery import Celery, bootsteps
from kombu import Queue
from kombu.common import QoS
class NoChannelGlobalQoS(bootsteps.StartStopStep):
requires = {'celery.worker.consumer.tasks:Tasks'}
def start(self, c):
qos_global = False
c.connection.default_channel.basic_qos(0, c.initial_prefetch_count, qos_global)
def set_prefetch_count(prefetch_count):
return c.task_consumer.qos(
prefetch_count=prefetch_count,
apply_global=qos_global,
)
c.qos = QoS(set_prefetch_count, c.initial_prefetch_count)
def setup_app_quorum(app: Celery, queues: list[str]):
app.steps['consumer'].add(NoChannelGlobalQoS) # type: ignore
app.conf.task_queues = [
Queue(
name=queue_name, exchange=queue_name, routing_key=queue_name,
queue_arguments={'x-queue-type': 'quorum'}
)
for queue_name in queues
]task.py
import random
from src.celery import app
import time
@app.task
def timeout_rabbitmq():
print('Recieved task')
time.sleep(random.randint(0, 15))
print('Task done')
return
@app.task
def nmap():
print('Recueved Nmap task')
import nmap
nm = nmap.PortScanner()
print(nm.scan(hosts='198.116.253.127', ports='', arguments='-sT'))run.py
from src.tasks import timeout_rabbitmq, nmap
import time
if __name__ == '__main__':
for i in range(50):
r1 = timeout_rabbitmq.apply_async(queue='queue')
r2 = nmap.apply_async(queue='queue')Run the app with a RabbitMQ, run the run.py script to surcharge the queue, and cut the connection between Celery and the broker (restart the container of the RabbitMQ for example).
Expected Behavior
All the workers must be up and be able to run the tasks after the reconnexion.
Actual Behavior
All workers are up, but only 4 still consume tasks from the queue.
The issue only appears when QoS is disabled.
A workaround has been found by disabling the worker_enable_prefetch_count_reduction configuration. Maybe the issue is in the reduction of the prefetch?
Activity
auvipy commentedon May 19, 2025
@Nusnus may be this is already fixed?
auvipy commentedon Jun 2, 2025
can you also reproduce it with celery 5.5.3?
Zalaxx commentedon Jun 4, 2025
I was able to reproduce the issue with Celery 5.5.3, RabbitMQ (docker image 4.1-managment-alpine), Python 3.13.3 and the code from the original issue. I also confirm that the option
worker_enable_prefetch_count_reduction = Falseis indeed a valid workaround.fix(consumer): skip prefetch reduction when per-consumer QoS is in ef…
test(consumer): cover celery#9512 fix at unit and smoke layers
test(consumer): tighten celery#9512 test coverage from review feedback
fix(consumer): address PR review feedback on celery#9512 fix
test(smoke): fix race in celery#9512 smoke tests barrier on task start
fix(consumer): skip prefetch reduction when per-consumer QoS is in ef…
Fix quorum-QoS reconnect smoke test after busy-worker tracking fix
test(smoke): scope acks_late cancellation to the liveness reconnect test
Fix free worker stalling after broker reconnect (AsynPool.flush clear…
Expect the prefetch reduction to be skipped under per-consumer QoS