Skip to content

fix: forceCleanWorker deletes the key holding the worker's current job - #1347

Open
voran wants to merge 1 commit into
actionhero:mainfrom
voran:fix/force-clean-working-on-key
Open

voran wants to merge 1 commit into
actionhero:mainfrom
voran:fix/force-clean-working-on-key

Conversation

@voran

@voran voran commented Nov 29, 2026 •

Copy link
Copy Markdown

Problem

Queue#forceCleanWorker reads the worker's current job from worker:<name>:<queues>, the key Worker#prepareJob writes and Queue#workingOn reads. It uses that job to build the error payload, but then deletes worker:<name> instead. Nothing in the library writes that key.

So whenever a worker is force-cleaned in the middle of a job, its job payload is left in Redis for good. That covers the scheduler's checkStuckWorkers, which is where it usually happens: a process that is killed mid-job stops pinging and is force-cleaned later. Worker#untrack and job completion delete the right key; only forceCleanWorker has the wrong name.

Over time these orphaned keys pile up, one per worker killed mid-job, each holding the full job payload. Nothing removes them: the worker is gone from workers, so neither workingOn/allWorkingOn nor a later forceCleanWorker finds them. In a long-running deployment that restarts workers on every deploy, we found tens of thousands of these keys.

Change

  • forceCleanWorker now deletes worker:<name>:<queues>, the same key Worker#untrack deletes, instead of worker:<name>.
  • A new test force-cleans workerA while it is in the middle of slowJob. It asserts that the job key exists before the clean, that the error payload is still built from it, and that afterwards the key is gone and the worker is no longer listed. The existing "removing all keys" test waits for the job to finish first, so the job key had already been removed by job completion and the test could not see this.

Verification

  • The new test fails on main (existsAfter is 1) and passes with the fix.
  • npm run lint, npm run build and the full jest suite pass locally against Redis: 14 suites, 116 tests.

🤖 Generated with Claude Code


Note

Medium Risk
Touches Redis cleanup for stuck/killed workers and stuck-job recovery paths; behavior change is a bugfix but affects production Redis state on force-clean.

Overview
Queue#forceCleanWorker now deletes worker:<name>:<queues> (the key that holds the in-flight job payload) instead of worker:<name>, which the library never writes. Error payloads are still built from the working-on data before cleanup, but orphaned job keys no longer accumulate when workers are killed mid-job (e.g. via stuck-worker checks on deploy).

A new integration test force-cleans a worker while slowJob is running and asserts the working-on key existed before clean, the returned error payload matches that job, the key is gone afterward, and the worker is removed from the registry.

Reviewed by Cursor Bugbot for commit 579628f. Bugbot is set up for automated code reviews on this repo. Configure here.

The job a worker is running lives at `worker:<name>:<queues>` (written by
Worker#prepareJob, read by Queue#workingOn, deleted by Worker#untrack and on
job completion). forceCleanWorker read it from there to build the error
payload, but then deleted `worker:<name>`, a key nothing ever writes. So every
worker force-cleaned in the middle of a job, including by the scheduler's
stuck-worker check, left its job payload in Redis permanently.

The existing "removing all keys" test force-cleans an idle worker, so it never
saw this; the new test force-cleans one mid-job.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant