The process lock is check-then-write, so two writers started together can both acquire it #227

Closed
opened 2026-10-06 01:49:46 +02:00 by clawbot · 1 comment
Collaborator

pidlock.Acquire reads the PID file, checks whether that process is alive, and then writes its own PID with os.WriteFile (internal/pidlock/pidlock.go:46-58). There is no O_EXCL and no flock. Two invocations started at the same instant can both pass the check and both run: duplicate cron lines, or a timer plus a manual run. README.md:187-190 says only one writer runs at a time, "so two writers can never corrupt the local index or the destination store". This is traced on next at 0700901, not reproduced as a race.

Definition of done

  1. Acquiring the lock is atomic: an OS file lock (flock) held for the life of the process, or creation with O_EXCL plus the existing liveness check for a stale file.
  2. A test holds the lock and asserts that a second Acquire fails while the first is held, and that it succeeds after release.
  3. make check passes.

Model: fable-5-1 (audit); opus-5-5 (issue)

`pidlock.Acquire` reads the PID file, checks whether that process is alive, and then writes its own PID with `os.WriteFile` (`internal/pidlock/pidlock.go:46-58`). There is no `O_EXCL` and no `flock`. Two invocations started at the same instant can both pass the check and both run: duplicate cron lines, or a timer plus a manual run. `README.md:187-190` says only one writer runs at a time, "so two writers can never corrupt the local index or the destination store". This is traced on `next` at `0700901`, not reproduced as a race. ## Definition of done 1. Acquiring the lock is atomic: an OS file lock (`flock`) held for the life of the process, or creation with `O_EXCL` plus the existing liveness check for a stale file. 2. A test holds the lock and asserts that a second `Acquire` fails while the first is held, and that it succeeds after release. 3. `make check` passes. Model: fable-5-1 (audit); opus-5-5 (issue)
clawbot self-assigned this 2026-10-06 01:49:46 +02:00
Author
Collaborator

The defect reproduced on next at cdc60c4: a test that starts many Acquire calls together got more than one lock. #258 makes the lock an flock on vaultik.pid, held for the whole run.

Model: opus-5-5

The defect reproduced on `next` at `cdc60c4`: a test that starts many `Acquire` calls together got more than one lock. https://git.eeqj.de/sneak/vaultik/pulls/258 makes the lock an `flock` on `vaultik.pid`, held for the whole run. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/vaultik#227