Repository navigation
Description
What's wrong
#10752 fixed self.ignore_result and added saferepr to the task-succeeded event, but it didn't address the _ensure_retryable note from @MehrazRumman. _success_was_stored still calls backend.get_state(), and the event block still calls backend.get_result(). Both go through get_task_meta() → _ensure_retryable().
on_failure runs in the worker's main process, so a blocked read there stalls the whole worker, not just one task.
Environment
- Celery:
5.7.0rc1onmain @ e3cc7cc53(editable install) - Python: 3.14.4, CPython
- OS: Linux, 64-bit
- Backend used in tests:
cache+memory://with a mocked_get_task_meta_for - Broker:
memory://(not relevant to this bug)
celery report
software -> celery:5.7.0rc1 (collider) kombu:5.7.0rc1 py:3.14.4
billiard:4.3.1 memory:N/A
platform -> system:Linux arch:64bit, ELF
kernel version:7.0.0-38-generic imp:CPython
loader -> celery.loaders.app.AppLoader
settings -> transport:memory results:cache+memory://
broker_url: 'memory://'
result_backend: 'cache+memory://'
deprecated_settings: None
Where
At e3cc7cc53:
celery/worker/request.py:844→backend.get_state(self.id)celery/worker/request.py:718→self.task.backend.get_result(self.id)
Reproduced
Mocked _get_task_meta_for to raise ConnectionError, always_retry=True, exception_safe_to_retry=True (the same predicate Redis and DB backends use).
_success_was_stored:
[REPRO-1] reads=4, sleeps=3
WARNING Failed operation failing_meta. Retrying 2 more times.
WARNING Failed operation failing_meta. Retrying 1 more times.
WARNING Failed operation failing_meta. Retrying 0 more times.
The except Exception only runs after _ensure_retryable gives up. With max_retries=3 that's 3 retries. With the default max_retries=inf (from result_backend_max_retries) it never gets there. @MehrazRumman measured 50+ sleeps (~200s) in their review.
Event block in on_failure:
[REPRO-2] event path sleeps=3
Even if _success_was_stored is fixed, the event block has the same problem for the same reason.
I wrote a minimal unit test locally (alongside the existing WorkerLostError tests in t/unit/worker/test_request.py) using a mocked backend whose _get_task_meta_for raises ConnectionError. I can submit it as a PR with strict xfail markers if that's the preferred approach.
Fix
Use _get_task_meta_for instead of get_state/get_result, which skips _ensure_retryable:
try:
return backend._get_task_meta_for(self.id)['status'] == states.SUCCESS
except Exception:
return Falsetry:
meta = self.task.backend._get_task_meta_for(self.id)
result = meta.get('result')
except Exception:
result = None
self.send_event('task-succeeded',
result=saferepr(result, self.task.resultrepr_maxsize),
runtime=None)A down backend then falls back right away, which is what the comment in _success_was_stored says the intent is.
Notes
- Only tested with
cache+memory://and a mocked backend. Worth double-checking on real Redis/DB with the backend actually unreachable — the retry path is the same, but a real-network failure could behave differently.
Activity
MehrazRumman commentedon Oct 25, 2026
@majidkhazaei You already suggested a fix . Why don’t you open a PR, push your code and check against existing test. Then figure out what went wrong from my side, that will be pretty cool . I will be very happy to see your solution and review your PR.
majidkhazaei commentedon Oct 25, 2026
Thanks for the nudge, @MehrazRumman.
I've just opened a PR with the fix and the tests. Here is the link: #10960
ChristianMurphy commentedon Oct 26, 2026
Reproduced with a real Redis result backend that's down. The stall needs
result_backend_always_retry=True. With the default, which is off,on_failure()doesn't wait on the backend on any version I tried. The title could name that setting.With it on, only the
acks_lateandreject_on_worker_lostsetup is a regression. 5.6.3 and 5.7.0rc1 requeue the task without touching the backend, and main blocks in_success_was_stored(). #10960 fixes that case.With default task settings, the worker also blocks on 5.6.3 and 5.7.0rc1, in
mark_as_failure(). That stall is older than #10752, and #10960 doesn't change it. It may need its own issue, which the author mentioned opening on #10960.What I ran
Request.on_failure()with aWorkerLostError, and the Redis result backend's port closed.result_backend_max_retriesis left at its default, which has no limit. Each run waits up to 30 seconds.always_retryoffalways_retryonmark_as_failure()acks_late,reject_on_worker_lostmark_as_failure()acks_late,reject_on_worker_lost_success_was_stored()acks_late,reject_on_worker_lost_success_was_stored()mark_as_failure()acks_late,reject_on_worker_lost"Finishes" means
on_failure()was done in under 0.1 s. Withalways_retryoff and default task settings, it raises theConnectionErrorfrommark_as_failure()on every version.[-]Worker stalls on _success_was_stored when the result backend is down[/-][+]Worker stalls on _success_was_stored when result_backend_always_retry=True and the result backend is down[/+]majidkhazaei commentedon Oct 26, 2026
Thanks for the thorough cross-version verification, @ChristianMurphy. The table makes the regression-vs-pre-existing split unambiguous, and it confirms exactly what #10960 is meant to do: restore 5.6.3 behavior.
Reading the table column-wise, #10960 (
efefb55) matches 5.6.3 on both rows:default+always_retryon → blocked inmark_as_failure()(pre-existing, not touched by this PR)acks_late+reject_on_worker_lost+always_retryon → requeues (the Don't fail a task whose SUCCESS was stored before the worker was lost #10752 regression, now fixed)So the PR removes the regression without introducing a new block or changing the older
mark_as_failure()path.Actions:
result_backend_always_retry=True.mark_as_failure()stall is out of scope here. I'll open a separate issue for it (tracking the approaches discussed: bounded retry budget from the main process, deferred write, or a time-based budget instead of a fixed count).On "Finishes vs raises": agreed — with
always_retryoff,mark_as_failure()raisesConnectionErroron every version, which is the expected behavior when retries are disabled. The stall only happens withalways_retry=True.Thanks again for testing against real Redis across 5.6.3, 5.7.0rc1, main, and the PR — this is exactly the kind of verification that makes the scope clear.
Merge upstream main into fix/worker-lost-after-link-before-store-10954