fix(cron): serialize get_due_jobs writes and add parallel state corruption regression tests - #16509
Closed
chinadbo wants to merge 1 commit into
Closed
fix(cron): serialize get_due_jobs writes and add parallel state corruption regression tests#16509chinadbo wants to merge 1 commit into
chinadbo wants to merge 1 commit into
Conversation
get_due_jobs() called load_jobs() and save_jobs() without holding _jobs_file_lock, creating a race with the locked mark_job_run() and advance_next_run(). Wrap get_due_jobs() with the lock (delegating to a new _get_due_jobs_locked() inner function) so all load→modify→save cycles are serialised. Add two regression tests: one verifying 3 concurrent mark_job_run() calls each land their correct last_status and last_run_at without overwrites, and a stress test confirming 10 parallel calls each increment their job's completed count to exactly 1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
chinadbo
force-pushed
the
fix/b3-cron-job-state-corruption
branch
from
April 28, 2026 02:04
34e68b3 to
e837c00
Compare
Contributor
|
Salvaged via #19874 onto current main - your commit authorship was preserved. Thanks! |
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.
Summary
get_due_jobs()incron/jobs.pycalledload_jobs()+ conditionalsave_jobs()without holding_jobs_file_lock, creating a race with concurrentmark_job_run()andadvance_next_run()calls from the thread poolget_due_jobs()body with_jobs_file_lockfor its entire load+save cycle, consistent with all other write pathsmark_job_run()calls verify no state overwrites; 10-thread stress test verifies all jobs land with correctlast_statusTest plan
tests/cron/test_jobs.py— 2 new concurrency tests inTestMarkJobRunConcurrency🤖 Generated with Claude Code