Skip to main content

bind_singleton

Function bind_singleton 

Source
pub fn bind_singleton(socket_path: &str) -> Result<Listener, BindSingletonError>
Expand description

Bind socket_path as a v2 local-socket listener, enforcing exactly-one-bind-per-name (the per-user-session singleton property).

Never unlinks the path up front. An earlier version of this logic (duplicated in running-process-broker-v2::main before this extraction) unconditionally ran remove_file before every bind attempt on Unix. Under a real concurrent-start race that let every one of N racing starters delete the current winner’s live socket and rebind over the freed path — so all N starters observed a successful bind instead of exactly one (running-process#899, soldr#2361/#2363’s singleton testing invariant). This function instead attempts the bind first with no cleanup. On an already-bound stale result, it serializes contenders with a sidecar lock, retries the bind under that lock, and only lets the holder that still sees a stale endpoint remove and reclaim it. Windows needs no cleanup step at all — the named pipe namespace is kernel-managed and a prior binding vanishes when that process exits.

On Unix, the parent directory of socket_path is created if missing before the first bind attempt.