lockutil

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lockutil provides cross-process advisory file locks used by cron, daemon, hooks, oauth, and swarm. Locks are held by the kernel for the lifetime of an open file handle, so process exit releases them without a stale-file reclaim protocol. The lock file itself is stable: holders never rename or remove it while another process may still have its inode locked.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLockHeld reports that another process or goroutine currently holds the
	// advisory lock. Callers may wait and retry until their own deadline.
	ErrLockHeld = errors.New("lockutil: lock is held")
	// ErrLockReleased reports an attempt to update metadata after Release.
	ErrLockReleased = errors.New("lockutil: lock is released")
)

Functions

This section is empty.

Types

type FileLock

type FileLock struct {
	// contains filtered or unexported fields
}

FileLock is an exclusive advisory lock held through an open file handle. Release is idempotent. The lock path remains on disk after release; deleting or replacing it would let different processes lock different inodes.

func TryAcquireFileLock

func TryAcquireFileLock(path string) (*FileLock, error)

TryAcquireFileLock attempts to take an exclusive advisory lock without waiting. A contended lock returns ErrLockHeld. The kernel releases a lock if its process exits, so an old unlocked file never needs stale reclamation.

func TryAcquireFileLockAt

func TryAcquireFileLockAt(root, path string) (*FileLock, error)

TryAcquireFileLockAt attempts to lock path while confining every component below root to a handle-relative traversal. root is the caller's trusted boundary and may itself be reached through a legitimate link; links and reparse points below it are rejected before metadata can be written.

func TryAcquireFileLockRoot

func TryAcquireFileLockRoot(root *os.Root, name, displayPath string) (*FileLock, error)

TryAcquireFileLockRoot attempts to lock name relative to an already-bound directory root. It is intended for lifecycle owners that must not resolve the root pathname again between validation and lock acquisition.

func (*FileLock) Release

func (lock *FileLock) Release() error

Release unlocks and closes the held file handle. It deliberately leaves the stable lock file in place. Repeated calls return the first release result.

func (*FileLock) WriteMetadata

func (lock *FileLock) WriteMetadata(data []byte) error

WriteMetadata replaces the diagnostic contents of the lock file while the caller holds it. Metadata does not establish ownership; the kernel lock does.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL