Delayed jobs stop processing after Postgres restart/maintenance. Pod stays Running, only a restart fixes it (6.5.2)

Infos:

  • Used Zammad version: 6.5.2
  • Used Zammad installation type: zammad-helm 15.7.0 (with our own customisations), Kubernetes (GKE
  • Operating system: Linux (container image on GKE)
  • Browser + version: N/A (background job problem)
  • Other info: External Cloud SQL PostgreSQL 16 and Elasticsearch. One scheduler replica, no liveness probe.

Expected behavior:

  • After the database is restarted or fails over and comes back, the scheduler’s background services ( ProcessDelayedJobs , ProcessScheduledJobs ) reconnect on their own. Delayed jobs keep being processed, or the process exits so Kubernetes restarts it.

Actual behavior:

  • After a Cloud SQL maintenance restart, the scheduler logs the errors below. ProcessDelayedJobs does not process jobs again.

  • The scheduler pod stays Running with 0 restarts, so nothing alerts.

  • Delayed jobs pile up ( in production). New tickets don’t reach Elasticsearch, so they are missing from search until someone restarts the scheduler.

  • A scheduler restart recovers it and drains the backlog.

    [Worker(host:... pid:1)] Error while reserving job: PQconsumeInput() FATAL: terminating connection due to administrator command
    SSL connection has been closed unexpectedly
    ERROR -- : BackgroundServices::Service::ProcessDelayedJobs#run() raised an error:
    There is an issue connecting with your hostname: <db-ip>.
    (ActiveRecord::DatabaseConnectionError)
    config/initializers/delayed_jobs_verify_db_connection.rb:9:in `recover_from'
    lib/background_services/service/process_delayed_jobs.rb:32 ...
    lib/background_services.rb:141:in `block in start_as_thread'
    ProcessScheduledJobs#run()  logs the same  DatabaseConnectionError .
    

Steps to reproduce the behavior:

  • Run Zammad 6.5.2 with an external PostgreSQL and the scheduler as a single pod.

  • Restart the database instance (a real restart; just killing connections with pg_terminate_backend recovers by itself).

  • The scheduler logs the errors above once the DB goes down.

  • Create a ticket after the DB is back. Delayed::Job.count keeps growing and the oldest job’s age keeps increasing. Nothing is processed and nothing is logged.

  • Restart the scheduler. The queue drains.

    What we already tried:

  • POSTGRESQL_OPTIONS=pool=50&reaping_frequency=10 , from this thread. We repeated the DB restart with it and the delayed-job thread still did not recover.

  • Related: #3149 and #6558. #6558 handles forked children, but our ProcessDelayedJobs runs as a thread ( start_as_thread in the trace).

    Questions:

  • Is there a supported way to make the scheduler’s background threads recover from a lost DB connection?

  • Does the #6558 fix, or any later release, cover thread-based services?

  • Is there a recommended health check (liveness probe or metric) for the background worker?

Thanks for the excellent report — the reproduction steps and the full stack trace make this unusually easy to follow, and the distinction between pg_terminate_backend (recovers fine) versus a real DB restart (stays stuck) is a really useful detail.

I can’t offer an official answer on whether #6558 covers the threaded services — that’s for the Zammad team to confirm. What I can share is what has worked for me in a similar setup (external Postgres + scheduler as its own pod): treat “the background threads died” as something Kubernetes should notice and act on, rather than expecting the process to exit cleanly.

Two practical pieces:

  1. A small liveness probe that checks queue progress instead of just the HTTP port — e.g. a script run inside the scheduler container that reads Delayed::Job.count and the age of the oldest pending job (via zammad run rails c or a direct SQL query against the delayed_jobs table), caches the values in a file, and exits non-zero if the oldest job’s age keeps growing across two consecutive checks while the pod stays Running. A liveness probe on that script turns “silent pile-up” into a pod restart, which is exactly the recovery you’re doing manually today — just automatically.

  2. If you use monitoring (Prometheus or similar), exporting delayed_jobs count + max age as a metric and alerting when the oldest job exceeds a few minutes gives you the same signal earlier, before search gaps appear for users.

It’s a workaround rather than a fix for the reconnect behaviour itself, but it removes the manual step in the meantime. One thing I’d be curious about: does ProcessScheduledJobs also stay dead after the restart, or only ProcessDelayedJobs? If scheduled jobs keep running while delayed ones stall, that might narrow down which connection handle is the one going stale.

Thanks, that’s helpful and we’ll implement the queue-age liveness probe.

To answer your question: in our test environment both ProcessScheduledJobs and ProcessDelayedJobs raised DatabaseConnectionError and stayed dead, with only Channel.fetch continuing.

In production only ProcessDelayedJobs stalled and ProcessScheduledJobs kept running, so it seems to depend on which service is mid-query when the DB drops.

We’ll keep this thread updated, and we’d still appreciate the Zammad team’s view on whether the threaded services are covered upstream.