Networking
Azure Load Balancer: diagnose idle TCP connections before changing the timeout
A production runbook for separating TCP flow expiry, keepalives, resets and application failures before changing an Azure Load Balancer rule.
An application reuses a TCP connection to a service behind Azure Standard Load Balancer. After a few quiet minutes, its first request fails or hangs; a fresh connection works. Health probes remain green. Increasing the timeout immediately can hide the symptom without identifying which component closed the flow or fixing the client’s behaviour.
This runbook follows an inbound TCP flow through a known load-balancing rule. The aim is to distinguish idle expiry from an application close or another intermediary. Use an authorised test client and workload, without production data.
Map the path and preserve evidence
Record UTC time, client and frontend addresses and ports, protocol, actual idle duration, error, serving backend if identifiable, and recent changes. Identify the frontend, rule, pool and probe. Include proxies, firewalls, NAT and application timeouts on the path: the shortest timeout may determine the outcome.
Export the effective configuration and its declarative version before changing anything. For example, with the correct subscription and read permissions:
az account show --query '{subscription:id,name:name}' -o json
az network lb rule list --resource-group <resource-group> --lb-name <load-balancer> -o json
az network lb probe list --resource-group <resource-group> --lb-name <load-balancer> -o json
For the matching rule, record the frontend, ports, protocol, idleTimeoutInMinutes and enableTcpReset. A different frontend or inbound NAT rule can have different settings. For an outbound flow, first identify the actual egress mechanism and its rule; do not assume inbound settings apply. If AKS manages the resource, identify its declarative owner before intervening.
Reproduce idle time, not just connection age
From the same kind of client and along the same path, establish a test connection, exchange a request, wait without traffic, then reuse the same socket. Repeat with waits shorter and longer than the observed threshold, and compare with a fresh connection. Check packet captures for TCP or application keepalives during the wait: a pause in business requests does not necessarily mean no packets were exchanged.
Correlate client and server logs and, where authorised, timestamped captures at both ends. A reset visible on only one side, or silence, does not establish its origin by itself: captures can be incomplete and other devices may intervene. Restrict captures to necessary metadata and protect the collected data.
| Observation | What to investigate |
|---|---|
| Failure after idle time near the rule’s timeout; a fresh connection works | Flow expiry is plausible. Compare multiple idle durations and other path timeouts. |
| Application closes first | Inspect connection pool, server, proxy and application policies and logs. |
| Fresh connections also fail | Do not assume idle expiry: inspect backend availability, probe, network and capacity. |
| An active flow is interrupted | Check loss, deployments, application limits and intermediaries; elapsed time alone does not prove idle expiry. |
A healthy probe shows that the probe contract is answered; it does not prove an idle client session survives.
Choose a bounded correction
For Standard Load Balancer the default idle timeout is four minutes; supported ranges depend on the rule type. An idle TCP flow is not guaranteed to remain available after expiry. With TCP reset enabled on the rule, Load Balancer sends resets to both endpoints at expiry; without it, packets can be silently dropped. A reset makes closure more explicit: it does not keep the connection alive or guarantee a business operation can be safely retried.
Depending on the application contract, test a targeted measure: evict stale pooled connections and reconnect, use a suitable keepalive on the inbound path, or adjust the rule timeout within documented limits. A keepalive must occur before the shortest timeout on the path and its cost must be acceptable. Do not automatically replay a write with an unknown outcome; use the application’s idempotency guarantees.
If changing a rule, use its declarative owner after reviewing the impact on every matching flow. Preserve the previous values, version, owner and restoration procedure. A timeout or reset change affects shared behaviour: schedule a window and use an isolated canary. Do not treat reset as a repair for a probe or backend failure.
Validate and decide
On the canary, confirm the effective configuration after deployment, then repeat tests below and above the relevant timeout. For keepalives, prove the exchanges and reuse; for resets, verify closure detection and reconnection. Also test a fresh connection, a representative business request and an operation whose failure cannot cause duplicate effects. Compare errors, latency and logs before and after over an agreed window, without exposing sensitive data.
Decision: expand only when observed behaviour meets the contract and other consumers remain healthy. Otherwise stop rollout, restore previous values through the same declarative channel and verify both the effective configuration and fresh and reused connections. Escalate if the responsible component remains unknown.