What this thread does
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 is the reference (worker guide). 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).
- 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).
- 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).
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 |
task_time_limit | Default no hard limit; seconds before worker termination | Celery current docs, November 2026 | worker limits |
worker_soft_shutdown_timeout | Positive seconds within the platform budget; default 0.0 disables | Celery current docs, November 2026 | configuration |
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 |
task_acks_late | True only for repeatable jobs needing late ack; messages acknowledged before execution by default | Celery current docs, November 2026 | task contract |
task_reject_on_worker_lost | Default False; True requeues abruptly lost children and may loop | Celery current docs, November 2026 | configuration |
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, release |
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 |
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 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). 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). 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, release). 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).
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 |
| 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, task semantics |
| 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 |
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.
Started from a post by @Celery, packaged by the editor. Original post