lock

package
v0.1.0-beta.16 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package lock serialises the processes that may write PHP-FPM configuration.

Two fpm-tune runs against one host is not a hypothetical: a `serve --apply` daemon and an operator running `fpm-tune apply` by hand is the ordinary way this goes wrong, and cron plus a slow scrape is the other. Both write the same fragments and both keep a backup of "the previous configuration" — so the second run backs up the first run's half-applied state and, on rollback, restores that instead of what was there originally.

The state file has the same problem from the other end: it is read at start and written whole, so two processes silently discard each other's learning.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("another fpm-tune process is already running")

ErrHeld reports that another fpm-tune process holds the lock.

Functions

func DefaultPath

func DefaultPath(statePath string) string

DefaultPath is the lock beside the state file. It covers the state, which is read whole and written whole, so two processes sharing one file would discard each other's learning.

func ResourcePath

func ResourcePath(dropInDir string) string

ResourcePath is the lock for a pool directory.

Separate from the state lock because they protect different things and are not interchangeable. Two runs given different --state paths took different state locks and then wrote the SAME pool fragments and the same backups, each taking the other's half-applied state as "the previous configuration" — the exact interleaving the locking was added to prevent, reachable by passing a flag. This one is keyed on what is actually being written.

It lives in a fixed directory, NOT in the backup directory. Keying it there made the lock defeatable by a flag: a daemon running with the defaults and an operator running `apply --backup-dir /tmp/b` computed different paths, both acquired cleanly, and both wrote the same pool file — the exact interleaving this exists to prevent, one flag over from the one it fixed.

Not the pool directory either: php-fpm includes that by glob, and a lock file that happened to match the pattern would be read as configuration.

Types

type Release

type Release func()

Release gives the lock up.

func Acquire

func Acquire(path string) (Release, error)

Acquire takes an exclusive lock, without blocking.

Non-blocking deliberately. A blocking acquire would queue an operator's interactive `apply` behind a daemon that holds the lock every interval, and leave them looking at a terminal that has not printed anything. Failing immediately with a clear message lets them stop the daemon and try again.

Jump to

Keyboard shortcuts

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