Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Queue#forceCleanWorkerreads the worker's current job fromworker:<name>:<queues>, the keyWorker#prepareJobwrites andQueue#workingOnreads. It uses that job to build the error payload, but then deletesworker:<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#untrackand job completion delete the right key; onlyforceCleanWorkerhas 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 neitherworkingOn/allWorkingOnnor a laterforceCleanWorkerfinds them. In a long-running deployment that restarts workers on every deploy, we found tens of thousands of these keys.Change
forceCleanWorkernow deletesworker:<name>:<queues>, the same keyWorker#untrackdeletes, instead ofworker:<name>.workerAwhile it is in the middle ofslowJob. 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
main(existsAfteris 1) and passes with the fix.npm run lint,npm run buildand 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#forceCleanWorkernow deletesworker:<name>:<queues>(the key that holds the in-flight job payload) instead ofworker:<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
slowJobis 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.