Documentation
¶
Overview ¶
Package bindiag holds the shared bind/listen retry + diagnostic helpers used by both the epoll and iouring engines. Linux-only (the build tag above excludes everything else); on non-linux the engines aren't compiled at all.
Two responsibilities:
BindWithRetry wraps unix.Bind with bounded exponential-with- jitter retries on transient EADDRINUSE. The race we mitigate is the kernel's per-port bind-table contention when the adaptive engine starts iouring + N epoll-loop sockets concurrently into the same SO_REUSEPORT group; one of the binds occasionally observes EADDRINUSE despite SO_REUSEPORT being set on every member of the group. The condition clears in microseconds.
Format produces the structured "addr=… SO_REUSEADDR=… …" string attached to bind/listen error messages so a real conflict (post-retry-budget) carries enough state to triage without reproducing.
Index ¶
Constants ¶
const BindRetries = 9
BindRetries is the maximum number of unix.Bind attempts. Sized so the total worst-case sleep budget covers the kernel-bind-table races we've observed in cluster matrix runs (sub-ms per race; <100ms across the entire SO_REUSEPORT group at startup) while bounding pathological kernel state at ~½ second.
Variables ¶
This section is empty.
Functions ¶
func BindWithRetry ¶
BindWithRetry calls unix.Bind on fd with sa, retrying on EADDRINUSE up to BindRetries times with exponential backoff + per-attempt jitter. Non-EADDRINUSE errors short-circuit immediately. The jitter matters because all SO_REUSEPORT-group members in a single process retry against the same kernel bind table; without it 12+ loops sleep+wake in lockstep and re-collide on every attempt.
Sleep schedule (worst-case, no early success):
attempt 1: [250 µs, 500 µs) attempt 2: [500 µs, 1 ms) ... attempt 8: [32 ms, 64 ms) total worst-case across 8 sleeps ≈ 128 ms (rare; typical: 0–1 ms).
func Format ¶
Format returns a one-line diagnostic snapshot useful when bind() or listen() fails. Captures the port being bound, the FD's actual SO_REUSE* socket-option values (in case a setsockopt didn't take effect), the list of other LISTEN sockets currently on the same port, and our process's open-FD count. Errors during diagnosis are reported inline so a malformed /proc cannot mask the original bind failure.
Types ¶
This section is empty.