A client opens their web browser, types in the address, hits enter, and waits—but the request takes too long, and the website doesn’t load. They’re met with the infamous “Error 408 Request Timeout."
Why did the 408 error appear? What can be done about it? While the error is client-side, the proxy sitting between the client and server can be a player in the timeout.
In this blog post, we expand upon our 2014 version, delving into what to consider on the HAProxy side when addressing this error.
What Does the HTTP 408 Request Timeout Error Mean?
The HTTP 408 status code is an error returned by the server when it doesn't receive a timely request from the client. The server can timeout under these conditions, and the client receives the 408 error.
If a load balancer sits before the server, managing incoming requests and distributing them across the fleet, the load balancer handling the connections can return a 408 error as well.
In this instance, the load balancer waits a specified period of time on an open connection for a full request. After this period of time has passed and the request is not received, the proxy closes the connection on behalf of the server. The browser reports the 408 error to the client to tell them, “you were too slow to send me a request on this connection, so I closed it.”
The 408 error only indicates a lack of request and is not indicative of what particularly happened to it. There can be various causes for the 408 error, and one in particular, TCP pre-connect, is one of the most common reasons for a timeout (we discuss further below).
The 408 error is not to be confused with the server-side 504 error that indicates a server acting as a proxy or gateway did not receive a timely response from the server upstream.
408 Error Synonyms/Variations
The 408 error is often referenced in various forms. The following errors all reference the same client-side issue—the request timed out:
408 Request Time-out
The Request Has Timed Out
408: Request Timeout
HTTP Error 408 - Request Timeout
Error Code 408
HTTP Status 408
What Causes 408 Errors?
Web browsers have a feature called “TCP pre-connect,” one of the most common causes of the 408 error. Before requesting any data from a server, the web browser will initiate a TCP connection with it.
The purpose is to speed up browsing for the client by saving time to establish these connections (pre-formed connections that can be used later). The problem is that, in some cases, these connections won’t be used, and the server or the proxy must decide on the inactivity.
The connections are closed when these pre-connections sit, with no requests following up to the server. When the browser starts using the connections it formed (and the connection has been closed due to timeout), it takes the data available (the error) and displays it to the client.
Another problem with the “TCP pre-connect” feature is that in the case of a website that receives a lot of traffic, it can maintain thousands (or even tens or hundreds of thousands) of pre-connections that only might be used. It is an expensive cost on the server side with a small positive effect on the client side.
While this blog post focuses on what can HAProxy users can do to workaround 408 errors, there are other causes of the request timeout beyond TCP pre-connect.
408 errors can be caused by the following client-side issues:
network connection problems
client firewalls and security blocking their requests
request configuration issues
browser extensions and settings
How to Prevent the 408 Request Timeout Error Message?
While the 408 error is a client-side issue in failing to send a full request on an open connection, changes to timeout settings can be made on the proxy side to close connections silently without sending unneeded information to browsers. These adjustments can be made in the configuration.
HAProxy’s Timeout Related to 408 Errors
In HAProxy’s configuration, two parameters may trigger a 408 error:
timeout http-request 10s timeout client 20s
The timeout http-request is the time you let a client send its request. If it is not set, then the timeout client will be used. If both of them are configured, the shortest value is used.
In a default configuration, when answering with a 408, HAProxy sends a message such as:
HTTP/1.0 408 Request Time-out Cache-Control: no-cache Connection: close Content-Type: text/html <html><body><h1>408 Request Time-out</h1> Your browser didn't send a complete request in time. </body></html>
This message is printed by some browsers.
Workaround in HAProxy
One way to work around this issue with HAProxy is to tell HAProxy to silently close the connection without sending any data.
You can add the line below in your defaults (or frontend/listen) section:
errorfile 408 /dev/null
This workaround will prevent browsers from printing the 408 error for the client. The line is not a solution to client-side issues.
408 Errors: Final Word
In summary, servers and proxies close connections with clients when full requests are not received promptly, which results in the 408 error displayed in the client browser. This error is often caused by TCP pre-connect (a browser feature that opens connections with a server before a request is made to accelerate the experience). Still, it can also result from network issues, firewalls and security, and other configuration settings. To prevent this error from appearing to the client, adjustments to timeout settings can be made to HAProxy to silently close unused connections.Subscribe to our blog. Get the latest release updates, tutorials, and deep-dives from HAProxy experts.