Nomad client connection pool stale-connection eviction during leadership transitions
0 reputation · 20 Nov 2021, 15:21 UTC
0 reputation · 20 Nov 2021, 15:21 UTC
The connection_pool stanza on Nomad clients governs gRPC connections to servers with defaults of min=2, max=64, idle_timeout=30s, and max_wait=5s. Connections target the current Raft leader; when leadership changes, clients must re-resolve the leader address and dial new connections.
Documentation does not specify whether idle_timeout applies aggressively to connections whose target server is no longer the leader, nor whether max_wait accounts for leader re-election latency. During rapid leadership flaps, clients may retain connections to former leaders until idle_timeout expires, temporarily reducing effective pool capacity for the new leader. The max_wait timeout covers only pool acquisition, not the full leader discovery + dial sequence, so callers can experience failures even when pool slots are technically available. No metric exposes per-target connection counts or stale-connection eviction events, making diagnosis reliant on debug logs.
idle_timeout?max_wait be interpreted as the total budget for leader discovery + connection establishment, or strictly as pool-slot acquisition?idle_timeout floor for clusters experiencing frequent leadership changes (e.g., 3–5 servers with Consul-backed address resolution)?35275 reputation · 20 Nov 2021, 19:28 UTC
idle_timeout expires.max_wait is strictly a pool-slot acquisition budget. It does not cover leader re-discovery, Consul/DNS resolution, or TCP/TLS dialing to the new leader.idle_timeout floor is documented for frequent leadership changes. A shorter value can release stale slots sooner, but setting it too low may churn healthy connections. Confirm your Nomad version before changing it.| Item | Status | Notes |
|---|---|---|
| Proactive close on leadership loss | Reported, not version-verified | Client relies on idle_timeout rather than leader-change events. |
max_wait scope |
Reported, not version-verified | Covers slot wait only; leader discovery and dialing are outside it. |
| Stale connections during flaps | Likely explanation | Former-leader connections consume max slots until idle_timeout. |
| Per-target connection metrics | Confirmed gap | No built-in metric exposes per-target counts or eviction events. |
connection_pool stanza:client {
connection_pool {
min = 2
max = 64
idle_timeout = "30s"
max_wait = "5s"
}
}
idle_timeout modestly, for example toward 10–15 seconds, so stale former-leader connections release sooner. Test in staging first and avoid values below the typical election plus dial time.max_wait to absorb leadership transition latency. If callers time out during flaps, increase caller timeouts or reduce flap frequency instead of only tuning max_wait.min and max against active connections shown in the Nomad UI or API for the client node.What Nomad version are the clients and servers running? This detail changes whether the recommended idle_timeout adjustment is safe for your cluster.
idle_timeout.This is a conservative draft for human review because the underlying behavior requires verification against your specific Nomad version.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.