Skip to content

Cold shutdown stores RETRY for an early-ack task it cancels, and nothing runs the task again #11079

Closed

Description

@ChristianMurphy

A cold shutdown stores the state RETRY for a running task it cancels when the task uses the default early ack. The message was acked when the task started, so nothing runs it again and the state stays RETRY. Main (9c2f238), prefork, Redis:

A 6 s task, kill -QUIT on the worker after 2 s, worker started again Result
Default settings State RETRY, nothing in the queue, not received again, 3 of 3

Early ack is documented to lose a task the worker doesn't finish. The report is about the state: RETRY says the task will run again, and a caller waiting on the result waits until its timeout.

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.
  • 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: 5.7.0 (9c2f238)

celery report Output:
software -> celery:5.7.0 (collider) kombu:5.7.0 py:3.14.6
            billiard:4.3.2 redis:8.1.0
platform -> system:Linux arch:64bit, ELF
            kernel version:6.18.44-fc-v378 imp:CPython
loader   -> celery.loaders.app.AppLoader
settings -> transport:redis results:redis://localhost:6379/1

broker_url: 'redis://:********@localhost:6379/0'
result_backend: 'redis://localhost:6379/1'
deprecated_settings: None

Steps to Reproduce

Required Dependencies

Minimal versions
  • Minimal Celery Version: 5.7.0
  • Minimal Broker Version: Redis 7.4
  • Minimal Result Backend Version: Redis 7.4
  • Python, kombu, OS and clients: N/A or Unknown

Python Packages

pip freeze Output:
billiard==4.3.2
celery @ main (9c2f238)
kombu @ main (445027e)
redis==8.1.0

Other Dependencies

Services

N/A

Minimally Reproducible Test Case

tasks.py, commands and output
# tasks.py
import time

from celery import Celery

app = Celery("tasks", broker="redis://localhost:6379/0",
             backend="redis://localhost:6379/1")


@app.task
def slow():
    time.sleep(6)
$ celery -A tasks worker -c 1 -l info &
$ python -c "from tasks import slow; print(slow.delay().id)"
0268eebc-24d7-4338-b5d2-b706028740a8
$ sleep 2; kill -QUIT %1
worker: Cold shutdown (MainProcess)
$ celery -A tasks worker -c 1 -l info &
$ sleep 12
$ python -c "from tasks import app; print(app.AsyncResult('0268eebc-24d7-4338-b5d2-b706028740a8').state)"
RETRY
$ redis-cli llen celery
(integer) 0

The second worker never logs the task as received.

Expected Behavior

A state that tells the caller the task won't run again, such as FAILURE or REVOKED. Or the task is sent again, as RETRY says.

Actual Behavior

The state is RETRY and the task is gone.

cancel_all_unacked_requests() cancels every active request that doesn't use acks_late and passes emit_retry=True for it (celery/worker/consumer/consumer.py:928). Request._announce_cancelled() then stores RETRY with the reason cancelled by Celery (celery/worker/request.py:446). For an acks_late task the broker redelivers the message, and no RETRY is stored. For an early-ack task nothing sends it again.

Which outcome would you want here? My lean is FAILURE with a reason that says the worker was shut down, since early ack is chosen so that a task isn't run twice. Should a maintainer confirm it, I can send a PR with a test.

Activity

  1. ChristianMurphy commented on Nov 12, 2026

    @ChristianMurphy
    ContributorAuthor

    For triage: this is a regression in 5.5.0. On 5.4.0 the same steps store FAILURE, and on 5.5.3 and main they store RETRY. That is one more reason to store FAILURE here.

    Where it comes from
  2. added 2 commits that reference this issue on Nov 19, 2026
    1741a14
    befb083
  3. added this to the 5.7.x milestone on Nov 22, 2026
  4. added a commit that references this issue on Nov 23, 2026
    992e9b5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions