cURL / Mailing Lists / curl-library / Single Mail


Re: weird timer behavior when re-using existing connection

From: Daniel Stenberg <>
Date: Tue, 17 Jun 2008 23:10:03 +0200 (CEST)

On Tue, 17 Jun 2008, David Lasker wrote:

> Hi, I am brand-new, very newbie libcurl user, so this may be a dumb
> question.

If it makes you feel any better, it certainly was not a dumb question... This
isn't documented in a crystal clear way.

> I am using the curl_multi interface to do HTTP POSTs. I am using libcurl
> 7.18.2 with c-ares on Linux.

And curl_multi_socket*() too I assume based on your further description.

> I am seeing some unexpected timer behavior when I make consecutive HTTP
> POSTs to the same URL and the connection gets reused.
> On the first HTTP POST, all looks good. My timer callback function is called
> 3 times with the following timeouts:
> 1. 0
> 2. 5000 (for the DNS lookup, I think)
> 3. 20000 (for the rest of the HTTP transaction)

Did you set any special timeout yourself? The 5000 is indeed for the possible
resend of the name resolving, but I'm not sure where 20000 would come from.
Possibly it is the 5000 times 4 (the default number of tries c-ares does).

> On the 2nd POST, I get just one timer callback with the timeout set to zero.

And what timeout would you expect for it?

> If I call curl_multi_timeout instead of using the timer callback, it returns
> -1 for the send POST.

Well, that's the same result - and using curl_multi_timeout() really is not
advicable when you use curl_multi_socket() anyway.

> If I delay the 2nd POST until the remote web server closes the connection,
> or POST to a different URL (so there is no connection reuse) all works fine.

But why would you need a timeout for it to be considered working fine?

> I realize there shouldn't be a DNS lookup or connection timeout on the 2nd
> POST, but I expected to need a timeout while waiting for the response from
> the remote web server?

Nope, libcurl has no default timeout for that.

Received on 2008-06-17