Skip to content

Make the flock the deploy lock itself #34

Open

Description

@wadewilliams

Context

The deploy lock is .git/deploy-lock, a JSON file holding the holder's PID and a timestamp. acquire() breaks a lock whose PID is no longer running (a stale lock).

#31 fixed a check-then-write race in acquire(): two deploys starting together could both see the lock free and both proceed. Acquirers now take an fcntl.flock on .git/deploy-lock.guard while they check and write the lock. That's correct, but there are now two mechanisms: the flock guard serializes acquirers, and the PID file plus stale-PID detection decide who holds the lock.

Proposal

Make the flock the lock. Hold an exclusive flock on .git/deploy-lock for the whole deploy, non-blocking, so a second deploy gets "locked" immediately:

  • The kernel releases a flock when its holder exits, however it exits, so there's no stale-lock case and no PID liveness check.
  • Keep writing the PID and timestamp into the file, but only for the "lock held by PID N" message.
  • release() becomes closing the file descriptor.

Worth it?

Possibly not. The current implementation is correct and tested, including an 8-process concurrency test. The gain is less code and one mechanism instead of two, and the PID-reuse edge case (a stale lock whose PID was reused by an unrelated process looks held) disappears. Do it if the lock is touched again for another reason.

Size

Small: about 30–50 lines in src/flow_deploy/lock.py and tests/test_lock.py. Low to medium risk: lock semantics on NFS-mounted .git would need a check, since flock over NFS varies.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions