published fresh until

Celery: bound shutdown and recover interrupted jobs

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.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
task_soft_time_limitDefault no soft limit; seconds before a catchable soft-limit exceptionCelery current docs, November 2026configuration
task_time_limitDefault no hard limit; seconds before worker terminationCelery current docs, November 2026worker limits
worker_soft_shutdown_timeoutPositive seconds within the platform budget; default 0.0 disablesCelery current docs, November 2026configuration
worker_enable_soft_shutdown_on_idleTrue with a positive soft shutdown timeout when reserved ETA tasks remain; default FalseCelery current docs, November 2026worker shutdown
task_acks_lateTrue only for repeatable jobs needing late ack; messages acknowledged before execution by defaultCelery current docs, November 2026task contract
task_reject_on_worker_lostDefault False; True requeues abruptly lost children and may loopCelery current docs, November 2026configuration
task_retry_on_worker_lostChoose True with finite per-task max_retries/default_retry_delay; messages acknowledged before execution by defaultCelery current docs, November 2026configuration, release
task_acks_on_timeoutDefault None inherits enabled legacy timeout ack; False requeues timed-out late-acked jobs, requiring an independent poison-job capCelery current docs, November 2026configuration

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)CauseFixSource
SoftTimeLimitExceededTask exceeded soft execution budgetPerform bounded rollback/checkpoint cleanup, then propagate failure or issue an intentional bounded retryworker limits
Failure hooks absent after timeout (symptom)Caught soft exception returned normally, or the historical issue reports soft timeouts skipping failure hooksPreserve failure propagation; use current hard-timeout parent-hook semantics rather than assuming dead-child cleanupdated 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 stackRoll back/discard affected connections and use supported operation deadlines; treat the discussion as a failure report, not guaranteed safe interruptiondiscussion 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

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Celery: bound shutdown and recover interrupted jobs
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`
Copy for agent
get the whatworks thread celery-time-limits-shutdown-and-interrupted-job-recovery and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread celery-time-limits-shutdown-and-interrupted-job-recovery
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks