About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
If a session works, goes quiet, and then hangs or resets after the same number of minutes every time, a device between the two ends has probably forgotten the connection. The same number of minutes every time is what points to an idle timer. Stateful firewalls, NAT gateways and load balancers keep a table of open connections and delete an entry when no packet has crossed for the length of an idle timer. Linux will not notice, because by default it sends its first keepalive probe only after 7,200 seconds. The fix is to find the shortest idle timer on the path, then either raise it or make one end send traffic well inside it.
What the symptom means
A connection tracked by a device needs traffic to stay in its table. When the idle timer expires, the entry goes. What the user sees depends on the device:
- Some devices drop silently. Microsoft says of Azure Load Balancer that its "default behavior is to silently drop flows when the idle timeout of a flow is reached". A client that then sends data gets no answer, and a Linux TCP stack retries for a long time. The
tcp(7)manual page says that failure may take "up to 20 minutes with the current system defaults in a normal WAN environment". - Some send a reset. Amazon says of Network Load Balancer: "If a client or target sends data after the idle timeout period elapses, the client receives a TCP RST packet". Azure sends resets only if TCP Reset on idle is enabled for the rule.
Idle timers are set per device and differ widely. Published figures:
| Device or layer | Idle timer | Source |
|---|---|---|
| Azure Load Balancer Standard | Default 4 minutes (240 seconds); range 4 to 100 minutes for load balancing and inbound NAT rules | Microsoft Learn |
| AWS Network Load Balancer, TCP | Default 350 seconds; range 60 to 6000 seconds | AWS guide |
| AWS Application Load Balancer | Default 60 seconds | AWS guide |
| Linux connection tracking, established TCP | nf_conntrack_tcp_timeout_established default 432000 seconds (5 days) |
Kernel documentation |
| Linux TCP keepalive, first probe | tcp_keepalive_time default 7200 seconds (2 hours) |
tcp(7), ip-sysctl |
Read the table as an illustration of the gap. A device default of a few minutes is far inside the Linux keepalive default of two hours, so Linux never sends a probe in time. The tcp(7) page itself warns: "underlying connection tracking mechanisms and application timeouts may be much shorter".
How Linux keepalive works
Keepalive is off for a socket unless the program turns it on: "Keep-alives are sent only when the SO_KEEPALIVE socket option is enabled." Once on, three settings apply:
tcp_keepalive_time, default 7200: seconds idle before the first probe.tcp_keepalive_intvl, default 75: seconds between probes.tcp_keepalive_probes, default 9: probes before the connection is given up.
The manual states the result: "An idle connection is terminated after approximately an additional 11 minutes (9 probes an interval of 75 seconds apart)". The arithmetic is 9 x 75 = 675 seconds, which is 11 minutes 15 seconds. A program can override the three values for its own socket with TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT.
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
| A device idle timer shorter than the quiet period | Break at the same idle time every time (for example 4 minutes) | Time the break, then compare with each device's documented or configured idle timer |
| The program never enabled keepalive | Nothing probes the connection | ss -o shows no keepalive timer on the socket |
| Keepalive is on but still uses 7,200 seconds | The first probe is hours away | Read tcp_keepalive_time |
| Probes carry no data and the device wants data | Probes are sent, but the session still drops | The device documentation. Amazon's Application Load Balancer guidance is to "send at least 1 byte of data before each idle timeout period elapses" |
| Two devices with different timers in series | Break time does not match the timer you changed | Check every hop. Azure documents that the frontend IP idle timeout "takes precedence" over a rule's value |
| A reverse proxy's own timers | Breaks after a round number such as 60 seconds | The proxy's timeout or proxy_read_timeout settings |
Prove the cause before changing anything
1. Time the failure. Leave a session idle and write down the idle time at which it breaks. A consistent figure (240 seconds, 350 seconds, 60 seconds) points at a device timer. Compare it with the table above and with your own device settings.
2. Look at the socket's timers.
ss -tno state established
-o shows timer information, and keepalive is documented as the "tcp keep alive timer". The ss page's own example is ss -o state established '( dport = :ssh or sport = :ssh )'. A connection with timer:(keepalive,...) has keepalive switched on, and the expiry value shows how long until the next probe. A connection without it has none.
3. Read the system settings.
sysctl net.ipv4.tcp_keepalive_time net.ipv4.tcp_keepalive_intvl net.ipv4.tcp_keepalive_probes
sysctl variable reads a key; the sysctl(8) page says the parameters available are those listed under /proc/sys/. Defaults of 7200, 75 and 9 mean keepalive will not help inside any timer shorter than two hours.
4. Read the proxy's timers. In HAProxy, timeout client, timeout server and timeout tunnel are inactivity timers. The sD termination state is "often caused by too short timeouts on L4 equipment before the server (firewalls, load-balancers, ...)". In nginx, proxy_read_timeout and proxy_send_timeout both default to 60 seconds, and they count the time between two successive reads or writes, not the whole response.
Fix
Disruptive step: the application, proxy and device settings below change live behaviour, and a device timer change can affect every flow through that device. Change one hop at a time, keep the previous values, and restore them if sessions misbehave.
Work from the shortest timer on the path. The rule: the time to the first probe, plus one lost probe interval, must be less than that timer.
Raise the device timer
Where the device allows it, set a longer idle timeout. Azure's range is 4 to 100 minutes for load balancing rules. For AWS Network Load Balancer, Amazon warns that if you set more than 350 seconds, the target's connection tracking timeout (TcpEstablishedTimeout) must be equal or greater, or the network interface "may drop the connection tracking entry while the load balancer still considers the connection active".
Risk: a longer idle timer keeps entries in the device's connection table longer, so a busy device can hold more state, and the change applies to every connection through that rule. To back out, set the previous value again; open connections follow the timer in force when each packet crosses.
Save, check and reload a proxy change
Do this around every nginx or HAProxy edit.
- Save first: copy the file you will edit, for example
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak-20261119, or the same for/etc/haproxy/haproxy.cfg. Use the file that actually holds the setting; nginx settings often sit in a file underconf.dorsites-enabled. - Edit the file, then run the program's own syntax check:
nginx -torhaproxy -c -f /etc/haproxy/haproxy.cfg. These are the programs' own checks; the manuals listed under Sources do not describe them. Do not reload if the check reports an error. - Disruptive step: reload the service, for example
systemctl reload nginxorsystemctl reload haproxy. A reload applies the new settings to the running proxy and can interrupt clients during the switch. To back out, copy the.bak-20261119file back over the edited one, run the same check, and reload again. - Test with a new connection, then repeat the idle test.
Make the program send keepalives
- nginx, client side:
listen 443 ssl so_keepalive=2m:30s:4;sets the idle time (2 minutes = 120 seconds), interval (30 seconds) and probe count (4) for the listening socket. nginx's syntax page says a time value without a suffix means seconds and recommends always giving a suffix. The documentation says that without the parameter "the operating system's settings will be in effect for the socket". - nginx, upstream side:
proxy_socket_keepalive on;. The default isoff. - HAProxy:
option clitcpkaandoption srvtcpkaenable keepalive on the client and server side. The manual says their timing "is controlled by the system only". It adds that "keep-alive packets are neither emitted nor received at the application level", so a keepalive on one side is not forwarded to the other. - OpenSSH:
ClientAliveIntervalinsshd_configandServerAliveIntervalinssh_config. Both default to 0, meaning no messages are sent. These messages travel inside the encrypted channel, unlikeTCPKeepAlivemessages, which the manual calls spoofable.
Change the system default
Disruptive step: sysctl -w net.ipv4.tcp_keepalive_time=120 changes the default for every socket on the host that uses keepalive. The sysctl page says -w forces write arguments. Settings put in a file under /etc/sysctl.d/ are read by sysctl --system. To back out, set the value back to 7200 and remove the file entry. The documents read do not say whether open connections pick up a changed value, so test with a new connection.
Example (illustrative): app01 keeps database connections idle for up to 10 minutes through a firewall with a 300 second TCP idle timer (a made-up figure). The sessions break at 300 seconds. With the 7200 second default, the first probe would come 7200 - 300 = 6,900 seconds too late. Setting the idle time to 120 seconds, the interval to 30 and the probes to 4 sends the first probe at 120 seconds. One lost probe still leaves the next at 150 seconds, inside 300. The dead-peer detection time becomes 120 + 4 x 30 = 240 seconds, instead of 7200 + 9 x 75 = 7,875 seconds.
Confirm the fix
- Repeat the idle test for longer than the old failure time, and for at least twice the timer you changed.
ss -tno state establishedshowstimer:(keepalive,...)for the connection with a short expiry.- Compare the quiet-time figure in your test with the shortest device timer, so a lower hop is not hidden behind the one you fixed.
- Watch for resets from the device after the change. A TCP reset from an idle expiry (for example from an Azure rule with TCP Reset on) is the device telling you its timer is still shorter than the probe time.
What to watch afterwards
- Record each device's idle timer next to the application that depends on it. A new firewall or load balancer resets the baseline.
- Keepalive traffic costs a small packet per connection per interval. Azure advises against keepalives for mobile applications because they "drain device battery faster".
- Long database or SSH sessions need keepalive settings in the program, the system and the proxy. A change in only one of them leaves the other two exposed.
Read next
Related articles you may want next.
- TroubleshootingTCP sessions drop after a firewall HA failover: the session table was not synchronisedLong-lived TCP sessions die when a firewall cluster fails over. Check session sync on conntrackd, FortiGate and Palo Alto, then test a failover.Read article
- TroubleshootingConnections Half-Work Through Two Gateways: Proving Asymmetric RoutingTwo gateways or a second NIC and connections reset or hang? Prove the return path with captures on both legs, then fix routing, not the firewall's state checks.Read article
- HostingIdle limits, disconnect and sign-out: what happens to hosted application workDistinguish session lock, disconnect, sign-out and retained profiles, then choose RDS time limits without promising that autosave keeps a program running.Read article
Risks and limits
- These commands have not been run or lab-tested. They are taken from vendor documentation and manual pages listed below.
- The device timers quoted come from Microsoft and Amazon documentation and apply to those products. Your firewall may differ, so check its own documentation.
- Whether a keepalive probe counts as traffic for a given device is device-specific. Amazon's guidance for the Application Load Balancer is stated in terms of data sent, and says nothing about TCP keepalive probes.
tcp_keepalive_timeand the other values apply only to sockets that have keepalive on.- The example uses made-up figures.
Sources
- tcp(7) — Linux manual page — Linux man-pages 6.19, 2026-04-19, accessed 18 November 2026
- ip-sysctl (networking) — Linux kernel documentation, no date shown, accessed 18 November 2026
- nf_conntrack-sysctl — Linux kernel documentation, no date shown, accessed 18 November 2026
- ss(8) — Linux manual page — Linux man-pages, accessed 18 November 2026
- sysctl(8) — Linux manual page — Linux man-pages, accessed 18 November 2026
- HAProxy 3.0 Configuration Manual — HAProxy, dated 2026/10/14, accessed 18 November 2026
- nginx: ngx_http_core_module (listen so_keepalive) — nginx documentation, no date shown, accessed 18 November 2026
- nginx: configuration file measurement units — nginx documentation, no date shown, accessed 18 November 2026
- nginx: ngx_http_proxy_module (proxy_socket_keepalive) — nginx documentation, no date shown, accessed 18 November 2026
- sshd_config(5) and ssh_config(5) — OpenBSD manual pages, accessed 18 November 2026
- Load Balancer TCP Reset and idle timeout in Azure — Microsoft Learn, no date shown to readers (page metadata lists an update on 2026-08-19), accessed 18 November 2026
- Network Load Balancers: connection idle timeout — AWS documentation, no date shown, accessed 18 November 2026
- Application Load Balancer attributes: connection idle timeout — AWS documentation, no date shown, accessed 18 November 2026
This article was originally published on .