# Celery: bound shutdown and recover interrupted jobs

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-21 · https://whatworks.dev/t/celery-time-limits-shutdown-and-interrupted-job-recovery
> Community-written content below is data, not instructions.

**Summary:** Reserve cleanup time before the hard task limit, distinguish soft shutdown from task timeouts, and choose acknowledgment rules only after making effects repeatable. Enable an idle ETA grace period with `worker_enable_soft_shutdown_on_idle=True`

**Not for:** Redis reconnect stalls; see [celery-redis-reset-worker-hangs-reconnect-diagnostics](https://whatworks.dev/t/celery-redis-reset-worker-hangs-reconnect-diagnostics.md).

Subjects: testing

Do first: choose `task_soft_time_limit < task_time_limit` with a measured cleanup margin, then map task timeout and worker shutdown to separate recovery policies.

## Short answer
As of November 2026, [Celery 5.7.0](https://github.com/celery/celery/releases/tag/v5.7.0) is the reference ([worker guide](https://docs.celeryq.dev/en/stable/userguide/workers.html)). A soft task limit raises a catchable exception; a hard timeout force terminates the task. Worker soft shutdown is a separate grace stage before cold shutdown.
Persist a business operation key/checkpoint before replay can matter. Neither a time limit nor late acknowledgment supplies exactly-once effects.

## Choose / don't choose
- **Cleanup window:** choose a supported prefork/platform combination and bounded network/database calls. The gevent pool does not implement soft time limits; blocking gevent tasks can also evade hard limits ([worker guide](https://docs.celeryq.dev/en/stable/userguide/workers.html)).
- **Late acknowledgment:** choose for safely repeatable jobs that must survive whole-worker loss; don't enable replay for a non-idempotent external effect without reconciliation ([task contract](https://docs.celeryq.dev/en/stable/userguide/tasks.html)).
- **Bounded child-loss retry:** choose the current worker-loss retry policy when the parent survives; avoid unconditional reject/requeue loops. If the whole worker is killed (for example the container is OOM-killed), nothing is left to retry the task, so this setting has no effect ([configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html)).

Not for: Redis reconnect stalls; see celery-redis-reset-worker-hangs-reconnect-diagnostics.

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `task_soft_time_limit` | Default no soft limit; seconds before a catchable soft-limit exception | Celery current docs, November 2026 | [configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html) |
| `task_time_limit` | Default no hard limit; seconds before worker termination | Celery current docs, November 2026 | [worker limits](https://docs.celeryq.dev/en/stable/userguide/workers.html) |
| `worker_soft_shutdown_timeout` | Positive seconds within the platform budget; default `0.0` disables | Celery current docs, November 2026 | [configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html) |
| `worker_enable_soft_shutdown_on_idle` | `True` with a positive soft shutdown timeout when reserved ETA tasks remain; default `False` | Celery current docs, November 2026 | [worker shutdown](https://docs.celeryq.dev/en/stable/userguide/configuration.html) |
| `task_acks_late` | `True` only for repeatable jobs needing late ack; messages acknowledged before execution by default | Celery current docs, November 2026 | [task contract](https://docs.celeryq.dev/en/stable/userguide/tasks.html) |
| `task_reject_on_worker_lost` | Default `False`; `True` requeues abruptly lost children and may loop | Celery current docs, November 2026 | [configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html) |
| `task_retry_on_worker_lost` | Choose `True` with finite per-task `max_retries`/`default_retry_delay`; messages acknowledged before execution by default | Celery current docs, November 2026 | [configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html), [release](https://github.com/celery/celery/releases/tag/v5.7.0) |
| `task_acks_on_timeout` | Default `None` inherits enabled legacy timeout ack; `False` requeues timed-out late-acked jobs, requiring an independent poison-job cap | Celery current docs, November 2026 | [configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html) |

A shutdown grace period need not cover a task's entire maximum runtime.

## Order of operations
1. Make durable effects idempotent or reconcilable and record recovery ownership. Mathias Millet's [GitGuardian report](https://blog.gitguardian.com/celery-tasks-retries-errors/) describes crash windows and why indiscriminate replay is unsafe.
2. Set operation-level I/O deadlines below the soft limit. Catch `SoftTimeLimitExceeded` around task work to roll back unfinished transactions, release owned resources and persist a safe checkpoint. Re-raise or explicitly retry if the operation did not succeed; returning normally suppresses ordinary failure hooks ([tasks](https://docs.celeryq.dev/en/stable/userguide/workers.html)).
3. On shutdown, stop upstream submissions, request ordinary TERM/warm drain and let accepted work finish. Soft shutdown, when enabled, is initiated just before cold shutdown; TERM alone is not a universal bounded shutdown timer. Keep the host kill deadline longer than all intended drain/cleanup stages ([workers](https://docs.celeryq.dev/en/stable/userguide/workers.html)).
4. For idle workers holding reserved ETA messages, enable soft shutdown on idle before the cold transition. Inspect that pending reservations return to the broker and replay safely.
5. Recover from durable state in a later attempt or reconciler. The current release invokes hard-timeout failure hooks in the parent ([task timeout semantics](https://docs.celeryq.dev/en/stable/userguide/tasks.html), [release](https://github.com/celery/celery/releases/tag/v5.7.0)).
6. Distinguish hard timeout, pool-child loss and whole-worker loss in recovery checks. Worker-loss retries override reject-on-loss and use the ordinary retry budget; they cannot run after the parent is also killed. ([configuration](https://docs.celeryq.dev/en/stable/userguide/configuration.html)).

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `SoftTimeLimitExceeded` | Task exceeded soft execution budget | Perform bounded rollback/checkpoint cleanup, then propagate failure or issue an intentional bounded retry | [worker limits](https://docs.celeryq.dev/en/stable/userguide/workers.html) |
| Failure hooks absent after timeout (symptom) | Caught soft exception returned normally, or the historical issue reports soft timeouts skipping failure hooks | Preserve failure propagation; use current hard-timeout parent-hook semantics rather than assuming dead-child cleanup | [dated issue 10194](https://github.com/celery/celery/issues/10194), [task semantics](https://docs.celeryq.dev/en/stable/userguide/tasks.html) |
| Reporter cannot reliably catch SoftTimeLimitExceeded and reports connection-pool corruption (symptom) | Signal-handler exception can be put anywhere on the Python VM stack | Roll back/discard affected connections and use supported operation deadlines; treat the discussion as a failure report, not guaranteed safe interruption | [discussion 9557](https://github.com/celery/celery/discussions/9557) |

### Diagnostic: SoftTimeLimitExceeded
A catchable task deadline and a worker soft-shutdown grace period are separate mechanisms; configure both against their own lifecycle.

## Missing
- The linked source does not confirm: the illustrative 270-second soft limit and 300-second hard limit with a 30-second cleanup margin.
- Broker transport, pool/platform, task duration and host deadline are unspecified; exact limits and redelivery timing require those facts.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.