Compare the stored StartTime before treating a PID as another instance [patch] - #185
Merged
Merged
Conversation
…e [patch] WritePidFile records the process start time, but nothing read it back. For an app run through the shared dotnet host, the process name and main module match every other dotnet process, so a stale PID recycled onto an MSBuild node or a dotnet tool blocked the app from launching. Both identity checks now also require the running process's start time to match the stored one within one second. PID files without a start time, and processes whose start time cannot be read, keep the previous check. Fixes #180 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018x3sGQTDEmvXP1cRdbmmkx
On Windows a freshly started process reports no main module until the loader has finished, so the tests recorded a null module path and then compared it against the loaded one. The helper now waits until its main module is readable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018x3sGQTDEmvXP1cRdbmmkx
The fallbacks for an unreadable start time only run when the OS denies access, which no live process in the test suite triggers. The comparison now takes the running start time as a delegate so its tolerance, UTC round trip and fallbacks are tested directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018x3sGQTDEmvXP1cRdbmmkx
|
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 #180
What was wrong
WritePidFilerecordsStartTime, butIsStoredProcessRunningandIsStoredProcessRunningByNamenever read it. An app launched through the shareddotnethost has the process namedotnetand the host's path as its main module, and so does every otherdotnetprocess. A stale PID file whose PID was later reused by an MSBuild node or adotnettool therefore looked like another instance, andExitIfAlreadyRunning()quietly exited until that process ended.Change
HasStoredStartTimecheck, used by both identity checks. The running process'sStartTimemust be within 1 s of the stored value. Both values are compared in UTC, and the tolerance covers the JSON round trip and clock granularity.StartTimeisdefault, which is how PID files written before the field existed deserializeInvalidOperationException/Win32Exception)Tests
IsAlreadyRunning_WithMatchingProcessButDifferentStartTime_ShouldReturnFalsecovers the acceptance criterion. The PID file describes a live helper process by PID, name and main module, with a start time an hour earlier. It fails with the fix reverted and passes with it.IsAlreadyRunning_WithMatchingProcessAndStartTime_ShouldReturnTrueconfirms that a genuine match is still detected.IsAlreadyRunning_WithMatchingProcessAndNoStoredStartTime_ShouldReturnTruecovers the fallback for older PID files.dotnet test: 29/29 passed on Linux (net10.0). The Release build had no warnings.This PR is independent of the separate fixes for #181 and #182 (PID-file write/read races), which touch different methods in the same file.
🤖 Generated with Claude Code
https://claude.ai/code/session_018x3sGQTDEmvXP1cRdbmmkx
Generated by Claude Code