Skip to content

Stop the result store wait before the worker's own time limits - #11183

Open
ChristianMurphy wants to merge 2 commits into
celery:mainfrom
ChristianMurphy:fix/store-wait-worker-time-limit
Open

ChristianMurphy wants to merge 2 commits into
celery:mainfrom
ChristianMurphy:fix/store-wait-worker-time-limit

Conversation

@ChristianMurphy

Copy link
Copy Markdown
Contributor

Note: Before submitting this pull request, please review our contributing
guidelines
& Anti AI spamming Guidelines. Before opening an AI based PR make sure you asked
in the discussion forum or in the related open issues first.

Description

The follow-up to #11014 that @auvipy asked for in #11014 (comment).

A worker started with --time-limit or --soft-time-limit still loses acks_late tasks during a short result backend outage. The wait from #11014 stops before the time limit of the task or of the message, but it did not know the worker's own limits, which the pool gives a task without one. The task was interrupted while it waited.

A 15 s outage, four tasks with task_track_started and acks_late:

Worker option main This PR
--time-limit 8 2 ran once, 2 never ran and are PENDING 4 ran once
--soft-time-limit 5 2 ran once, 2 stored FAILURE without running 4 ran once
--time-limit 8, 45 s outage 0 ran, 4 PENDING 4 ran once

The change:

  • The worker's main process sends the tracer the limits its pool enforces: prefork both, gevent the hard one, the other pools none. They travel on a copy of the request and the tracer takes them off before the task starts, so they are not in task.request and a retry does not publish them.
  • The wait stops before the next limit to fire. Once a soft limit has fired it stops before the hard one. On main the last state of a task that hit its soft limit was stored without a wait.

It doesn't add a setting or a public name. A worker without a time limit sends the same request as before, and the lookup takes about 0.6 microseconds per task.

Not changed here, and the same on main today: with result_backend_always_retry the wait keeps retrying past the limit, and a store attempt that blocks (dropped packets with a long socket timeout) can run into the limit.

Tests and other runs
  • Smoke: two new tests in t/smoke/tests/test_backend_outage.py, a worker with --time-limit=8 and one with --soft-time-limit=5. Both fail on main (one of five tasks never runs) and pass here.
  • Unit: new tests for the tracer, for the wait in Backend.store_result and for both execute_using_pool paths. 24 of them fail on main's source, and each of eight bugs I planted fails at least one.
  • Same result as main, each 4 of 4 once: no limit, task_time_limit = 8, time_limit=8 on the message, both worker options together, and task_time_limit = 6 with --soft-time-limit 30.
  • A task that hits --soft-time-limit while the backend is down stores FAILURE once the backend is back, as on main. A task on the threads pool with --time-limit (not enforced there) stores its result after the outage, as on main. A task that retries doesn't see a custom header, as on main.
  • t/unit/worker, t/unit/tasks, t/unit/concurrency, t/unit/app/test_trace.py and the base, Redis and database backend tests as tox runs them (python -bb): 2934 passed, and one Redis backend test that fails on main here too. flake8 and isort are clean.
  • Celery main (07ec498c4), kombu main (c706ebe6), Python 3.13, Redis 7.0 as broker and as a separate result backend, prefork with 2 processes.
  • Not run: the gevent and eventlet pools, RabbitMQ outside the smoke tests, the integration suite.

While a task runs, its pool process waits out a short result backend
outage, and stops before the task's time limit so the task can still be
requeued. The wait knew the limits of the task and of the message, but
not the worker's --time-limit and --soft-time-limit, which the pool
gives a task without a limit. Such a task was interrupted while it
waited: with --time-limit it never ran, with --soft-time-limit it stored
FAILURE without running.

The worker now sends the tracer the limits its pool enforces. They
travel on a copy of the request, so they are no header of the task and
no retry publishes them. Pools that enforce no limit send none.

The wait stops before the next limit to fire. Once the soft limit has
fired it stops before the hard one: before, the last state of a task
that hit its soft limit was stored without any wait.
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.83%. Comparing base (ce68a20) to head (913841f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11183   +/-   ##
=======================================
  Coverage   91.82%   91.83%           
=======================================
  Files         153      153           
  Lines       22314    22341   +27     
  Branches     2798     2806    +8     
=======================================
+ Hits        20490    20517   +27     
  Misses       1529     1529           
  Partials      295      295           
Flag Coverage Δ
unittests 91.81% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant