curl-library
RE: Keepalive
Date: Tue, 18 Mar 2008 13:47:07 +0100 (CET)
On Tue, 18 Mar 2008, Gabriel Kälin wrote:
>> When the time comes and libcurl wants to re-use a connection, it first
>> checks if the connection seems dead and if so it kills it and creates a
>> fresh one instead. At times it'll even try to use the connection only to
>> find it died and then it creates a new one.
>
> I'm wondering how curl decides whether a connection is dead if it hasn't
> received any FIN-packets from the server.
Then it can't see that it is dead but will instead attempt to use the
connection, and when it fails to do that it will create a new connection
instead.
> I've seen cases where libcurl tried to re-use an old TCP-connection that had
> been dropped by a stateful firewall between the client and the server.
Exactly, since there's no way for libcurl to tell that this happened.
> In that case curl seems to block indefinitely instead of establishing a new
> TCP connection.
curl or libcurl? libcurl uses non-blocking connections so it doesn't block on
the socket functions and it shouldn't block on this kind of situation either -
it's not even a very rare situation.
> How can curl avoid this situation without stopping to re-use connections?
It can't avoid it, it just needs to deal with it. And it can minimise the
occurance by the use of TCP KEEPALIVE messages - but then you need to enable
them in your app.
> The only way I see would be CURLOPT_LOW_SPEED_LIMIT and
> CURLOPT_LOW_SPEED_TIME. Am I missing an obvious solution to this problem?
Those options have no effect when libcurl doesn't do anything, which is the
time when idle connections typically are "killed" by NATs/firewalls.
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2008-03-18