Fix unique-job lock leak in inline testing mode - #3
Closed
lovitt wants to merge 1 commit into
Closed
Conversation
lovitt
force-pushed
the
fix/inline-unique-job-zombie-lock
branch
from
June 26, 2026 14:49
8c7a4b5 to
af64897
Compare
lovitt
force-pushed
the
fix/inline-unique-job-zombie-lock
branch
2 times, most recently
from
June 26, 2026 15:00
d9f8995 to
ab9ae4f
Compare
The provisional/final lock split added in 0.15.0 assumes the block passed to `lock_for_scheduling!` only enqueues the job. Under inline testing mode (`Cloudtasker::Testing.inline!`) the block also executes the job synchronously, which releases the job's lock via the execute middleware. Step 3 then re-acquires a "final" lock that nothing will ever release, so a subsequent enqueue of the same unique job is wrongly rejected for the full lock TTL. Skip the final-lock step under inline execution: the job has already run and released its lock by the time scheduling returns. The async (production) path is unchanged. Adds an integration spec (two successive inline enqueues of the same unique job both run) and a unit spec (the lock is not promoted to the final TTL in inline mode).
lovitt
force-pushed
the
fix/inline-unique-job-zombie-lock
branch
from
June 26, 2026 15:11
ab9ae4f to
62213f8
Compare
Member
Author
|
Superseded by the upstream PR keypup-io#173, which carries the same fix based on |
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
In inline mode (
Cloudtasker::Testing.inline!), a unique job runs only the first time it's enqueued — later enqueues of the same job are silently rejected.lock_for_scheduling!(added in 0.15.0) takes a provisional lock, yields to enqueue the job, then takes the final lock. That final lock is meant to be released later, when the job runs — the execute middleware unlocks it.But in inline mode the job runs during the yield, so it unlocks before the final lock is even taken. The final lock is then set after the job has already finished, leaving it with no future run to release it. It lingers for the full
lock_ttland rejects later enqueues of the same job (on_conflict: :reject). 0.14.0 did a plainlock!; yield, so this is a regression.Fix
Skip the final-lock step in inline mode, where the job has already run and released its lock. The async/production path is unchanged:
inline_mode?is guarded bydefined?(Cloudtasker::Testing), which is false in production (same idiom asCloudTask.backend).Tests
Integration spec (both inline enqueues run) and unit spec (lock not promoted to the final TTL).