{"modulePath":"github.com/windsorcli/cli","version":"v0.10.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package stacklock\n\n## Variables\n\n```go\nvar DefaultTimeout = 5 * time.Minute\n```\nDefaultTimeout is a suggested wait duration for callers that want to opt into waiting on a contended lock (e.g. via --lock-timeout) rather than the fail-immediately default. It is no longer applied automatically: a caller-supplied timeout of 0 means \"fail immediately,\" matching terraform's own -lock-timeout=0 default, rather than silently blocking for minutes with no output.\n\n## Functions\n\n```go\nfunc With(ctx context.Context, rt *runtime.Runtime, operation string, timeout time.Duration, fn func() error) error\n```\nWith acquires an exclusive stack lock against the runtime's context and runs fn while holding it. The lock is released on return — including on panic — via deferred Release. operation labels what the caller is doing (\"up\", \"apply\", \"destroy\", \"bootstrap\", \"plan\") so concurrent operators see the holder's intent in busy-error messages. timeout is how long to wait on contention before failing; 0 fails immediately (matching terraform's own -lock-timeout=0 default) rather than blocking silently.\n\n## Types\n\n```go\ntype LockBusyError struct {\n\tPath   string\n\tHolder *LockInfo\n}\n```\nLockBusyError is returned by Acquire when the timeout elapses with the lock still held. Holder is best-effort and may be nil when the lock-file body is absent or unparseable.\n\n```go\nfunc (e *LockBusyError) Error() string\n```\nError renders a human-readable description of the lock contention; the Holder fields are included when known so operators can identify the blocker without opening the file.\n\n```go\ntype LockInfo struct {\n\tID        string    `json:\"id\"`\n\tOperation string    `json:\"operation\"`\n\tMode      Mode      `json:\"mode\"`\n\tWho       string    `json:\"who\"`\n\tVersion   string    `json:\"version\"`\n\tProjectID string    `json:\"project_id\"`\n\tContext   string    `json:\"context\"`\n\tCreated   time.Time `json:\"created\"`\n\tPID       int       `json:\"pid\"`\n}\n```\nLockInfo records who holds a stack lock and why. Persisted into a sidecar file next to the lock so a blocked contender can name the holder in its busy error and operators can identify the holding process.\n\n```go\nfunc NewInfo(rt *runtime.Runtime, operation string) LockInfo\n```\nNewInfo constructs the LockInfo persisted into the holder-info sidecar for a given runtime and operation label. The result is diagnostic only — Acquire writes it next to the lock so the next contender's busy error can name the holder and the holding PID.\n\n```go\ntype Mode int\n```\nMode distinguishes writer (Exclusive) from reader (Shared) acquisition. Acquire takes every lock as Exclusive. Shared is reserved, and plan cannot use it: plan runs terraform init and writes into the context's TF\\_DATA\\_DIR, so two plans would race.\n\n```go\nconst (\n\tExclusive Mode = iota\n\tShared\n)\n```\n\n```go\ntype Release func() error\n```\nRelease frees a previously-acquired lock. Implementations must be idempotent: calls after the first one return nil.\n\n```go\ntype Shims struct {\n\tshims.Shims\n}\n```\nShims holds the shared system call primitives of the stack lock.\n\n```go\nfunc NewShims() *Shims\n```\nNewShims returns a Shims with every field set to its real implementation.\n\n```go\ntype StackLock interface {\n\tAcquire(ctx context.Context, info LockInfo, timeout time.Duration) (Release, error)\n\tInspect(ctx context.Context) (*LockInfo, error)\n\tIsHeld(ctx context.Context) (bool, error)\n\tClearStale(ctx context.Context, reason string) error\n}\n```\nStackLock coordinates exclusive access to a single (projectRoot, contextName) tuple across windsor invocations. A given StackLock instance is constructed per operation; implementations are not required to be safe for concurrent in-process reuse of one instance.\n\n```go\nfunc ForRuntime(rt *runtime.Runtime) (StackLock, error)\n```\nForRuntime returns the StackLock for the runtime's context — the same lock that With acquires. It is exposed so operator-facing recovery (windsor unlock) can inspect a lock and clear its stale holder info without duplicating the path derivation. Returns an error when the runtime is nil or has not been configured yet (empty scratch path).\n\n```go\nfunc NewLocalFlockLock(lockPath string) StackLock\n```\nNewLocalFlockLock returns a StackLock backed by a local advisory file lock at lockPath. The lock file's parent directory is created on first Acquire. Single-host coverage only; network filesystems where flock semantics are unreliable (NFS) will degrade silently.\n\n","path":"github.com/windsorcli/cli/pkg/provisioner/stacklock","name":"stacklock","synopsis":"","isRedistributable":true}
