Skip to content

Jobs aborted during graceful shutdown are left locked instead of failed #663

Backlog

Description

@biplabku

When a graceful shutdown aborts running jobs (after gracefulShutdownAbortTimeout), the worker logs them as failed but the failure is never written. The jobs stay locked with no last_error and only become runnable again after the 4 hour stale-lock sweep.

Repro: graphile-worker 0.18.0, Node 22, Postgres 16. run({ connectionString, concurrency: 4 }) with default signal handling. A task that waits 8 s and rejects when helpers.abortSignal fires. Add 4 jobs, send SIGTERM 2 s after they start.

The log shows, for each job:

Failed task 1 (chaos, 3015.64ms, attempt 1 of 25) with error 'aborted'

but right after the process exits:

select id, attempts, locked_at is not null, run_at - now(), last_error from graphile_worker._private_jobs;
 1 | 1 | t | -00:00:03 |
 ...

A second worker started afterwards doesn't pick them up (still 4/4 locked after 30 s). Same result in 4/4 trials, with the default 5 s abort timeout too, and whether the app handles signals itself (await runner.stop()) or leaves it to Worker.

Cause, I think: in src/worker.ts the unbatched failJob({...}) and completeJob(job) calls aren't awaited, so the pool finishes shutting down and the process exits before the outcome query runs. (#641 is about the same un-awaited calls, from the error side.)

Awaiting them in the worker fixes it locally: after shutdown all 4 jobs are unlocked with last_error = 'aborted' and run_at ~3 s out, and the next worker runs them (4/4 trials). I haven't measured whether awaiting there costs throughput; tracking pending outcome promises and waiting for them before the pool releases might be the cleaner fix.

Repro script and results: https://github.com/biplabku/queue-chaos/tree/main/repros/graphile-shutdown

Happy to send a PR for either approach.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions