Repository navigation
Throw for a PID file that can't be read or written instead of reporting another instance [patch] - #209
Open
matt-edmondson wants to merge 2 commits into
Open
Throw for a PID file that can't be read or written instead of reporting another instance [patch]#209matt-edmondson wants to merge 2 commits into
matt-edmondson wants to merge 2 commits into
Conversation
…ng another instance [patch] An access failure on the PID file or its folder, such as one left owned by root after a run under sudo, was read as another instance running, so the app exited 0 on every launch with no message. Only a lock held by another process now counts as another instance. Any other failure that outlasts the retries is thrown, naming the PID file. Fixes #187 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2iZzaJLpHHri8a4vS
…s on The check now takes the platform as a parameter, so each platform's lock error code is covered whichever operating system runs the tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2iZzaJLpHHri8a4vS
|
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.



Fixes #187
What was wrong
ReadPidFileStateandTryWritePidFiletreated everyIOExceptionandUnauthorizedAccessExceptionas "another instance holds the PID file". An access failure doesn't clear by itself, though. A PID file or folder left owned by root (one run undersudois enough) madeShouldLaunch()returnfalseon every launch, andExitIfAlreadyRunning()exited 0 with no message.Change
ERROR_SHARING_VIOLATION/ERROR_LOCK_VIOLATION(0x20/0x21in the HRESULT)FileShare.Noneas the bareEWOULDBLOCKerrno (11). I checked this on .NET 10.EWOULDBLOCKis35UnauthorizedAccessExceptionorIOExceptionof the same kind. The message names the PID file, says this is not another instance, and points at the ownership cause. The original exception is kept asInnerException.ShouldLaunch,ExitIfAlreadyRunningand the internals, and the README feature line.Of the two options the issue offered, I chose throwing over "launch without the guarantee": a loud failure seemed safer than silently dropping the guarantee the library exists for. No public API is added. Callers that never saw an exception before can now get one in this fault case, which is the point of the change. If you'd rather call that
[minor], change the tag.Tests
TryWritePidFile_WhenPidFileCannotBeReplaced_ShouldReturnFalseasserted the old behaviour. It is now..._ShouldThrowNamingThePidFile.IsAlreadyRunning_WhenPidFileCannotBeRead_ShouldThrow,ShouldLaunch_WhenPidFileCannotBeReadOrWritten_ShouldThrowInsteadOfReturningFalse. Both put a directory where the PID file belongs, which fails on every platform and for root.ShouldLaunch_WhenPidFolderIsReadOnly_ShouldThrowInsteadOfReturningFalse. This is the issue's case B: a folder the user can't write to. Folder modes don't stop root, so it is Inconclusive on Windows and for a privileged process.ShouldLaunch_WhenPidFileIsHeldExclusively_ShouldReturnFalseWithoutThrowingstill passes. It shows that a real lock is still read as another instance on Linux.Verified locally on Linux / .NET 10:
Not covered
#188 (wall-clock steps defeating the start-time check) touches the same PID-file path. It is left for its own PR because its preferred fix, holding a lifetime lock, is a larger redesign.
Generated by Claude Code