Skip to content

Record process start time in server.pid to detect pid reuse - #42

Merged
hiyamamo merged 1 commit into
mainfrom
pid-identity-check
Jul 19, 2026
Merged

hiyamamo merged 1 commit into
mainfrom
pid-identity-check

Conversation

@hiyamamo

Copy link
Copy Markdown
Owner

Summary

  • server.pid now records the process start time (from ps -o lstart=) on a second line next to the pid.
  • readServerPid compares 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.
  • The value is only compared for equality, so the lstart format is irrelevant and this works on both linux and darwin. Files without a start time (written by older versions, or when ps is unavailable) fall back to the previous liveness-only check, so upgrades are seamless.
  • All consumers benefit through the shared helper: ws-dev server (stop-prior), ws-dev server stop, and ws-dev status.

Closes #34

Test plan

  • New TestReadServerPidStartTime: a live pid with a mismatched recorded start time is reported dead and the file removed; pidFileContents round-trips as alive
  • Existing TestReadServerPid covers the no-start-time (legacy) format
  • make check passes

🤖 Generated with Claude Code

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>
@hiyamamo
hiyamamo merged commit f39cf35 into main Jul 19, 2026
3 checks passed
@hiyamamo
hiyamamo deleted the pid-identity-check branch July 19, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stopPrior が pid 再利用時に無関係なプロセスへ SIGTERM しうる

1 participant