Documentation
¶
Overview ¶
Package filelock is an inter-process exclusive lock on one path.
It is the mechanism internal/common/distfiles uses for its per-distfile locks, generalised to any path: the lock file is created with O_EXCL, held with flock(2) LOCK_EX for as long as the holder lives, and carries the holder's PID for the human who finds it. Whether a lock is live is decided by the kernel, never by the PID: a lock file whose flock can be taken belongs to a process that has died, and is reaped — but only after confirming the path still names the same inode, so a reap can never remove a live lock that replaced the dead one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Wait = 2 * time.Minute Poll = 25 * time.Millisecond )
Wait bounds how long Acquire waits for a live holder, and Poll is the interval between attempts. They are variables so tests can shorten them.
var ErrLocked = errors.New("lock is held by another process")
ErrLocked is returned by Acquire when another live process kept the lock for longer than Wait.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is a held lock. Release gives it up.
func Acquire ¶
Acquire takes the exclusive lock at path, waiting up to Wait for a live holder and reaping the lock file of a holder that has died. purpose is written into the lock file so a person who finds it knows what holds it.
On timeout the error wraps ErrLocked and names path and the holder's PID. Any other failure is wrapped naming path and does not wrap ErrLocked.