Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("another instance is already running")
ErrAlreadyRunning is returned by TryAcquire when another instance owns the socket path and is actively listening.
Functions ¶
This section is empty.
Types ¶
type Acquired ¶
type Acquired struct {
// contains filtered or unexported fields
}
Acquired represents a successfully acquired singleton lock. Call Release() when the current process is done to clean up the socket file.
func TryAcquire ¶
TryAcquire attempts to claim the given UNIX socket path as a singleton lock.
Strategy:
- Try net.Listen("unix", path). - Success → we are the owner; return Acquired. - EADDRINUSE → check if the existing socket is stale (connect fails). If stale, remove it and retry once. If live, return ErrAlreadyRunning.
- If the directory does not exist, it is created automatically.
func (*Acquired) Listener ¶
Listener returns the underlying net.Listener so callers can hand it off to an IPC server (e.g. ipc.ListenFrom) without closing and re-opening the socket, which would introduce a race window.
After calling Listener(), the caller owns the net.Listener. Release() will still remove the socket file but will no longer close the listener (since the caller now manages its lifetime).