Update only_one to use flock (advisory lock) instead of pidfile #35225
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.
The implementation of
only_one.rb
(#only_one_running?
) reads a pidfile and (if it exists) sends akill 0
to see if a previously-started process is still running. If not, the current process writes its PID to that file and deletes it with anat_exit
hook on shutdown.This script had two (known remaining) issues, both related to the
at_exit
hook deleting the pidfile on shutdown:at_exit
hook when they exit, causing the file to be deleted before the process actually exited;at_exit
hook and the process actually shutting down, causing the file to be deleted before the process actually exited.These issues could be dealt with by fixing them individually (see #35069 for a fix to 1), or by removing the
at_exit
entirely and depending only on thekill 0
rather than the file-existence to determine if another process is still running.This PR offers an approach using advisory file locks (see
flock(2)
) viaFile#flock
, which ends up being simpler than the approach using pidfiles andkill 0
.Testing story
We didn't have existing test coverage for this script, so I added a simple test
OnlyOneTest
covering basic behavior usingfork
that fails onstaging
but passes with either this PR or #35069.Reviewer Checklist: