A connection timeout describes a situation where a client fails to connect to a server after waiting for a predetermined length of time, loses their connection, or is otherwise unable to connect successfully. However, connection timeouts can also happen on the server side. When a server can't process a client request quickly enough, that connection will also drop (often called a "response timeout"). 

Your system triggers a timeout when it determines or believes there's no working network connection. This could happen due to a number of factors:

  • Poor network performance and latency

  • Network congestion

  • Misconfiguration(s)

  • Backend server faults or failures

  • Firewall settings incompatibility

  • Browser issues

  • A failed TCP handshake

Connection timeouts are frustrating since they prevent clients from accessing services, yet they're symptoms of these underlying issues—not causes in themselves. A connection timeout can generate a 408 Request Timeout status code, but this isn't considered a server reply. Timeouts occur when replies aren't sent back to the client. The server determines that it's waited long enough to make a connection and prioritizes other clients as a result.

What makes connection timeouts useful?

If servers spun their wheels waiting endlessly to connect with clients, this waiting would start impacting application performance—and especially so at scale. Servers and clients stuck in a connection loop aren't actually performing a job and are thus underutilized. This prevents you from getting the most performance and reliability from your infrastructure. 

This is a bigger problem for servers that synchronously process requests, or fulfill them in the order they're received. Even while a connection attempt is pending, the process consumes CPU threads, memory, database connections, and more. 

Envision yourself in a coffee shop, waiting in line to place your order. The customer ahead of you (a fellow client) has finally arrived at the register, but they're taking ages to choose what they want. This prevents the cashier and barista (the servers) from taking other orders, creating a bottleneck. After a certain point, the employee (likely more politely than the server) might ask them to step aside to serve those with requests waiting. After a certain period of time (a "cooldown" period), the cashier and original customer will try again.

Set connection timeouts cautiously

Connection timeouts do come with caveats. First, increased timeout intervals can decrease application throughput, since the server will wait for longer periods without doing work. This problem might not present itself immediately, but will quickly emerge as resources are held captive. 

Second, many default timeout settings are too lengthy—even set automatically to "infinite" in some instances. This could negatively impact application availability and performance at scale. Setting connection timeouts explicitly can help prevent these issues.

How does HAProxy handle connection timeouts?

HAProxy allows you to specify time formats in your preferred unit (such as milliseconds), set enforceable thresholds, and define separate timeouts for clients and servers. HAProxy even supports varied timeouts for both brief and long-lived connections based on your specific use case. 

To learn more about connection timeouts, check out our HAProxy Configuration Manual.