Documentation
¶
Overview ¶
Package lock provides cross-process advisory file locking.
File acquires an exclusive lock on the file at path, blocking until the context is cancelled (or its deadline elapses). TryFile does the same but returns ErrContended immediately if the lock is already held. In both cases the returned release function drops the lock and closes the underlying file descriptor.
The lock is released automatically by the kernel on process termination (including crash), so no stale-lock recovery is needed.
The lock file at path is created if it does not exist. It is never unlinked — flock is keyed by inode, not path, and unlinking could create a window where two processes lock different inodes at the same path.
This is the canonical file-locking helper for Seshat. Callers should prefer it over rolling their own platform-specific code.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrContended = errors.New("file lock is held by another process")
ErrContended is returned by TryFile when the lock is already held by another process.
Functions ¶
func File ¶
File acquires an exclusive advisory lock on the file at path, blocking until the lock is acquired or ctx is cancelled. It returns a release function that drops the lock and closes the underlying file descriptor.
Pass a context with a deadline (e.g. context.WithTimeout) to bound the wait. Pass context.Background() to block indefinitely.
Types ¶
This section is empty.