Help us shape the future of Go! Take the 2026 Go Developer Survey

flock

package
v0.81.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package flock provides best-effort advisory file locking using flock(2).

This is used for cross-replica coordination (e.g. preventing duplicate ACME requests). Note that flock(2) does NOT work reliably on NFS volumes: on NFSv3 it depends on the NLM daemon, on NFSv4 Linux emulates it via fcntl locks with different semantics. Callers must treat lock failures as non-fatal and proceed without the lock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock

func Lock(ctx context.Context, path string) (*os.File, error)

Lock acquires an exclusive advisory lock on the given file path. It creates the lock file if it does not exist. The lock attempt respects context cancellation by using non-blocking flock with polling. The caller must call Unlock with the returned *os.File when done.

func Unlock

func Unlock(f *os.File) error

Unlock releases the lock and closes the file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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