Repository navigation
Record process start time in server.pid to detect pid reuse - #42
Merged
Merged
Conversation
The pid file previously held only the pid, so after a reboot (or plain pid recycling) `ws-dev server` / `server stop` / `status` could mistake an unrelated process for the recorded server and send it SIGTERM. The file now stores the pid plus its start time (`ps -o lstart=`, compared only for equality). readServerPid treats a live pid whose start time differs from the recorded one as stale and removes the file. Files without a start time (older versions, or ps unavailable) keep the previous liveness-only behavior. Closes #34 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
server.pidnow records the process start time (fromps -o lstart=) on a second line next to the pid.readServerPidcompares the recorded start time with the live process's; a mismatch means the pid was recycled (classic pidfile pitfall, e.g. after a reboot), so the file is treated as stale instead of SIGTERMing an unrelated process.lstartformat is irrelevant and this works on both linux and darwin. Files without a start time (written by older versions, or whenpsis unavailable) fall back to the previous liveness-only check, so upgrades are seamless.ws-dev server(stop-prior),ws-dev server stop, andws-dev status.Closes #34
Test plan
TestReadServerPidStartTime: a live pid with a mismatched recorded start time is reported dead and the file removed;pidFileContentsround-trips as aliveTestReadServerPidcovers the no-start-time (legacy) formatmake checkpasses🤖 Generated with Claude Code