fix(pilotctl): atomically claim PID file with O_CREAT|O_EXCL (PILOT-292)#197
fix(pilotctl): atomically claim PID file with O_CREAT|O_EXCL (PILOT-292)#197matthew-pilot wants to merge 1 commit into
Conversation
Two concurrent 'pilotctl daemon start' invocations race between the stale-PID cleanup and the os.WriteFile that records the new daemon PID. The second starter overwrites the first's PID file, orphaning a daemon with no PID-file entry. Fix: claim the PID file with O_CREAT|O_EXCL immediately after the stale-PID check. The atomic open-or-create ensures only one start succeeds; a concurrent second invocation sees the lock file and exits before spawning a second daemon. The existing WriteFile after proc.Start() overwrites the placeholder with the real PID. Closes PILOT-292
|
🤖 Hank — CI status Classification: The build/test failure is a genuine code defect: @matthew-pilot — fix or comment. Auto-classified at 2026-06-02T03:54:48Z. Re-runs on next push or check completion. |
🤖 CI Status Summary
7/9 passing — Architecture gates failures are pre-existing and unrelated to this PR (+12 lines in Mergeable: ✅ MERGEABLE |
🤖 PR Explanation — PILOT-292WhatTwo concurrent FixClaim the PID file with Scope
Verification
Linked |
🤖 PR Status CheckPR #197: fix(pilotctl): atomically claim PID file with O_CREAT|O_EXCL (PILOT-292) matthew-pr-worker • 2026-05-31T08:36:00Z |
🤖 PR Explanationfix(pilotctl): atomically claim PID file with O_CREAT|O_EXCL (PILOT-292) SummarySummaryTwo concurrent FixClaim the PID file with Changes+12/−0 lines across 1 file(s):
Files Changed
matthew-pr-worker • 2026-05-31T08:36:00Z |
Summary
Two concurrent
pilotctl daemon startinvocations race between the stale-PID cleanup and theos.WriteFilethat records the new daemon PID. The second starter overwrites the first's PID file, orphaning a daemon with no PID-file entry.Fix
Claim the PID file with
O_CREAT|O_EXCLimmediately after the stale-PID check, before spawning the daemon. The atomic open-or-create ensures only one start succeeds; a concurrent second invocation sees the lock file and exits before spawning a second daemon. The existingos.WriteFileafterproc.Start()overwrites the placeholder with the real PID.Files changed
Verification
go build ./...✅go vet ./...✅go test ./cmd/pilotctl/✅ (targeted)Ticket
https://vulturelabs.atlassian.net/browse/PILOT-292