Against race conditions and duplicate cron entries#10
Merged
Conversation
- **File Locking**: Uses `flock` to ensure only one update process runs at a time - **Atomic File Operations**: Uses `mv` instead of `cat` for atomic file updates - **Duplicate Prevention**: Tracks processed jobs to prevent duplicate cron entries - **Unique Temp Files**: Uses process-specific temporary files to prevent conflicts - **Proper Cleanup**: Automatic cleanup of temporary files on script exit
vedmaka
requested changes
Jul 8, 2025
| # Use flock to ensure only one update process runs at a time | ||
| ( | ||
| flock -x 9 || { | ||
| log "Another update is already running, skipping this event" |
Member
There was a problem hiding this comment.
This failover won't be triggered unless you provide -n parameter because -x waits for the lock to release by default
But we probably don't want to have this failover in the first place, otherwise it would discard the events after the one that triggred the update so it's possible that the contab ends up in not desired state. Example with this failover in place:
- An event received for labels update
- The update of the crontab started
- Labels updated again shortly until the crontab update is completed
- The last even is discarded and you end up with crontab state not matching the labels
So I would not add -n but instead remove the failover || {...} so it would not confuse anyone looking at it
Contributor
Author
There was a problem hiding this comment.
Thanks, you are right.
|
🐳 The image based on d2671039 commit has been built with |
vedmaka
approved these changes
Jul 9, 2025
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.
flockto ensure only one update process runs at a timemvinstead ofcatfor atomic file updates