Conversation
After a termination signal the process may still run finally/fail hooks or wait on a child; service managers often follow up with SIGKILL. Release the lock as soon as the signal arrives (via a dedicated signal.Notify channel) so the lockfile does not survive a hard kill. Make Lock.Release idempotent for the signal + normal-exit paths. Fixes creativeprojects#548
This branch has not been deployed
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
Fixes #548 — profile lockfiles can remain after SIGINT/SIGTERM.
defer runLock.Release()only runs whenrun()returns. After a termination signal the process may still spend time in run-after-fail / finally hooks or waiting on a child; systemd (and similar) often follows up with SIGKILL (TimeoutStopSec). If that happens beforerun()returns, the lockfile is left behind.This is distinct from the closed attempt in #627 (which assumed
os.Exitskipped defers — it does not, because that defer is registered first inmain). The fix here is early release on signal, not fixing defer ordering.Changes
signal.Notifychannel (does not compete with the sharedsigChanused to forward signals to child processes).Lock.Release()idempotent (sync.Once) so the signal and normal-exit paths are safe under-race.run()after SIGTERM; normal return still releases;Release()is idempotent.Test plan
go test -race -count=1 . -run TestLockgo test -race -count=1 ./lock/ -run 'TestRelease|TestLock'Fixes #548