Daniel Marcotte Daniel Marcotte - 2 months ago 24
HTTP Question

How to configure Squid connection|read|write timeout per Request instead of Globally

Setup

Suppose I have two different HTTP clients using the same Squid instance.

The first client, named ClientA, has an aggressive Http read/write and connection timeout of 5 seconds. The other Client, named ClientB, has a very relax timeout of 120 seconds.

My Squid server configurations looks like that:

connect_timeout 1 minute
read_timeout 1 minute
write_timeout 1 minute


Scenario 1

The ClientA, sends a request to ServerX (through Squid) that will wait 45 seconds before accepting the connection and then immediately answers back.

Question 1

The ClientA will timeout after 5 seconds, but will Squid notice that and close the outbound the connection or wait for ServerX response (in 40~ seconds) and fail to write back the result to the ClientA that is no longer listening?

Scenario 2

The ClientB, sends a request to ServerY (through Squid) that will wait 61 seconds before accepting the connection and then immediately answers back.

Question 2

The ClientB will NOT timeout, but Squid should timeout after 60 seconds and send an Http Timeout 408 to the ClientB, right?

Global question

Is there any way to setup Squid so we can set the timeouts by Request instead of globally at the service level?

Answer

Important note: squid's behavior regarding timeouts can change depending on the protocol used. In the case of HTTPS, it cannot inspect the tunneled connection's HTTP headers so it cannot honor any of the Connection, Proxy-Connection, or Keep-Alive: timeout=xx values.

Scenario 1

Squid will close the outbound connection as soon as it notices the client going away.

Scenario 2

Squid will indeed time out, but the result will depend on the protocol used. In the case of HTTP, it will return "504 Gateway Time-out" and add an additional header "X-Squid-Error: ERR_READ_TIMEOUT 0".

In the case of HTTPS, it will simply close the connection, because it cannot read or inject headers that would be meaningful to the client.

Global question

Not in the squid configuration itself. If you want fine-grained control over your persistent connections' timeouts, you should do so in your clients.

For the record, here are the time-out settings squid will try to honor for persistent connections:

client <-> squid: client_persistent_connections, persistent_request_timeout

squid<->server: server_persistent_connections, pconn_timeout, read_timeout (for HTTPS)