Error Codes Wiki

HTTP Keep-Alive Connection Errors — Persistent Connection Troubleshooting

Warning5xx server error

Overview

Troubleshoot HTTP Keep-Alive and persistent connection errors including premature connection closure, timeout mismatches, and connection pool exhaustion.

Key Details

  • HTTP/1.1 uses persistent connections (Keep-Alive) by default to reuse TCP connections across requests
  • Connection: keep-alive header explicitly requests a persistent connection in HTTP/1.0
  • Keep-Alive timeout defines how long an idle connection stays open before the server closes it
  • Connection pool exhaustion occurs when all persistent connections are in use and new requests queue
  • HTTP/2 multiplexing eliminates the need for multiple parallel TCP connections

Common Causes

  • Server Keep-Alive timeout shorter than client's expected idle time, causing unexpected connection drops
  • Connection pool exhausted on the client side — too many concurrent requests to the same host
  • Proxy closing idle connections before the backend's keep-alive timeout
  • Network equipment (firewalls, NAT) terminating idle TCP connections silently

Steps

  1. 1Align keep-alive timeouts: server timeout should be slightly longer than proxy timeout
  2. 2Increase connection pool size in your HTTP client library for high-concurrency scenarios
  3. 3Implement connection retry logic: catch connection reset errors and retry on a new connection
  4. 4Monitor connection pool usage with metrics to detect exhaustion before it causes errors
  5. 5For Nginx: set keepalive_timeout 65s and keepalive_requests 1000
  6. 6Upgrade to HTTP/2 to eliminate connection pool issues through multiplexing

Tags

keep-alivepersistent-connectionconnection-pooltimeouttcp

Related Items

More in 5xx Server Error

Frequently Asked Questions

Apache defaults to 5 seconds, Nginx to 75 seconds. Browsers typically keep connections open for 60-120 seconds. Align these values to prevent premature closures.