Repository navigation
Stop a scheduled run from overlapping itself - #11
Merged
Merged
Conversation
crond starts a job on schedule whether or not the previous one finished, and a run can easily outlast its own interval -- downloads are slow. Two copies of the same job then race on the same playlist. Scheduled runs go through a wrapper that holds a lock for the duration, so a second start stands down and says so. It exits 0, since a skipped schedule is not an error and cron would otherwise complain every time. The lock is per job rather than global. A long weekly-exploration must not cancel weekly-jams: skipping a different playlist entirely is worse than letting the two overlap, and the runs the guard exists to prevent are a job racing itself. Where flock is missing the wrapper runs the job unlocked and says so, because an overlapping run is a lesser problem than a playlist that never gets built. The web UI's own guard is unaffected; it never applied to cron, which execs the binary directly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Audit finding 6.
The bug
crondstarts a job on schedule whether or not the previous one finished, and a run can outlast its own interval — downloads are slow, and #9 caps monitoring alone at two hours. Two copies of the same job then race on the same playlist.This is the mirror image of finding 5: the web UI has an "already running" guard, but cron never touched it, since
docker/start.shexecs the binary directly.The fix
Scheduled runs go through
docker/explo-run.sh, which holds a lock for the duration. A second start stands down with a log line and exits 0 — a skipped schedule isn't an error, and cron would otherwise complain every time.The lock is per job, not global. A long
weekly-explorationmust not cancelweekly-jams: silently skipping a different playlist for the week is worse than letting two runs overlap, and what the guard exists to prevent is a job racing itself. Whereflockis missing it runs unlocked and says so, for the same reason.The lock is held on a file descriptor rather than passed as
flock FILE -c PROG, which keeps the exit status unambiguous —flockcan then only fail because the lock is held, never because the job did. That matters becauseexploitself exits 1 on a failed run.Testing
docker/explo-run_test.shcovers: running when free, a second copy of the same job skipping, a skip exiting 0, a different job not being blocked, the lock releasing when the run ends, and the command's exit status passing through. All six pass.Caveat on how I ran them. There's no shell harness in CI (the pipeline is golangci-lint only), and this machine has neither
flocknor a Docker daemon, so I couldn't execute against busybox's real binary. I ran the suite against a stand-in implementing busybox'sflock [-n] FDform viafcntl.flock, so the contention is genuine OS advisory locking — what's untested is busybox's exact CLI parsing of that form, not the script's logic. The fallback branch was separately confirmed by running with noflockon PATH at all.Both scripts pass
sh -n, and I checked the generated crontab line renders as intended.🤖 Generated with Claude Code