Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Connection retry do not work with purge option at startup #10102

@fes-cailabs

Description

@fes-cailabs

Checklist

  • I have verified that the issue exists against the main branch 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 report in 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 main branch of Celery.

  • I have included the contents of pip freeze in 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:

poetry run celery -A celeryworker.tasks report

software -> celery:5.6.2 (recovery) kombu:5.6.2 py:3.12.1
            billiard:4.2.4 py-amqp:5.3.1
platform -> system:Windows arch:64bit, WindowsPE
            kernel version:11 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:amqp results:disabled

broker_url: 'amqp://guest:********@127.0.0.1:5672//'
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:

pip freeze
amqp==5.3.1
billiard==4.2.4
celery==5.6.2
# Editable install with no version control (celeryworker==0.1.0)
-e c:\projects\test\celeryworker
click==8.3.1
click-didyoumean==0.3.1
click-plugins==1.1.1.2
click-repl==0.3.0
colorama==0.4.6
kombu==5.6.2
packaging==26.0
prompt_toolkit==3.0.52
python-dateutil==2.9.0.post0
six==1.17.0
tzdata==2025.3
tzlocal==5.3.1
vine==5.1.0
wcwidth==0.6.0

Other Dependencies

Details

N/A

Minimally Reproducible Test Case

Details

I take the exemple from celery repository and I put it to a new empty repository:
https://github.com/celery/celery/blob/main/examples/tutorial/tasks.py

If I use the following command to launch the worker, it's works:

celery -A celeryworker.tasks worker --loglevel=info --concurrency=1

By works I mean launching the worker without a broker service result on retry.

[2026-02-09 09:56:37,557: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée.
Trying again in 2.00 seconds... (1/100)

[2026-02-09 09:56:41,590: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée.
Trying again in 4.00 seconds... (2/100)

if I add the purge option, it didn't work:

celery -A celeryworker.tasks worker --loglevel=info --concurrency=1 --purge
celery -A celeryworker.tasks worker --loglevel=info --concurrency=1 --purge
[2026-02-09 09:56:57,122: CRITICAL/MainProcess] Unrecoverable error: OperationalError('[WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée')
Traceback (most recent call last):
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 474, in _reraise_as_library_errors
    yield
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 461, in _ensure_connection
    return retry_over_time(
           ^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\utils\functional.py", line 318, in retry_over_time
    return fun(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 941, in _connection_factory
    self._connection = self._establish_connection()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 863, in _establish_connection
    conn = self.transport.establish_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\transport\pyamqp.py", line 203, in establish_connection
    conn.connect()
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\amqp\connection.py", line 324, in connect
    self.transport.connect()
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\amqp\transport.py", line 132, in connect
    self._connect(self.host, self.port, self.connect_timeout)
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\amqp\transport.py", line 187, in _connect
    self.sock.connect(sa)
ConnectionRefusedError: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\celery\worker\worker.py", line 203, in start
    self.blueprint.start(self)
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\celery\bootsteps.py", line 112, in start
    self.on_start()
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\celery\apps\worker.py", line 133, in on_start
    self.purge_messages()
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\celery\apps\worker.py", line 188, in purge_messages
    count = self.app.control.purge(connection=connection)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\celery\app\control.py", line 475, in purge
    return self.app.amqp.TaskConsumer(conn).purge()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\celery\app\amqp.py", line 314, in TaskConsumer
    return self.Consumer(
           ^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\messaging.py", line 414, in __init__
    self.revive(self.channel)
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\messaging.py", line 427, in revive
    channel = self.channel = maybe_channel(channel)
                             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 1139, in maybe_channel
    return channel.default_channel
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 960, in default_channel
    self._ensure_connection(**conn_opts)
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 460, in _ensure_connection
    with ctx():
  File "C:\Python_setup\Python3121\Lib\contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "C:\Projects\test\CeleryWorker\.venv\Lib\site-packages\kombu\connection.py", line 478, in _reraise_as_library_errors
    raise ConnectionError(str(exc)) from exc
kombu.exceptions.OperationalError: [WinError 10061] Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée

Expected Behavior

We expect that the broker_connection_retry_on_startup configuration work for purge option

Actual Behavior

There is no retry on broker connection for the purge option

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions