cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: blocking on dns resolving

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 18 Dec 2011 23:53:57 +0100 (CET)

On Sun, 18 Dec 2011, Pedro Larroy wrote:

> (lib/asyn-ares.c:288)

> My interpretation is that there's this poll call waiting for the dns query
> to finish in the ares_channel associated with the current curl_handle thus:

But that's not right. At least that's not how it is meant to work.

When the multi interface function is called due to activity on a socket and
the multi handle's internal state is in CURLM_STATE_CONNECT then it will call
the funtions that then trickles down to a call to
lib/asyn-ares.c:waitperform(). The handle should then move on to the
CURLM_STATE_WAITRESOLVE state if the resolve didn't immediately happen.

As you can see, it calls the function with a timeout of 0. It is just a
single-time check if there's anything to do, and it then returns all the way
back to your application. It is not a block.

> * It will block the whole program until the current dns reply is
> recieved, which goes against the paradigm of the multi interface usage
> with asynchronous IO.

Why would it? It checks with a timeout of 0, that means it returns
immediately.

> * If that wasn't bad enough, the select has a timeout of 0.

Why is that bad? It means it won't block!

> * I have already observed degradation and blocking which was very
> detrimental and tracked down to this.

Then you've found a bug we should fix. I still don't see it though.

> I think it's going to be difficult to fix since the multi api exposes one
> socket perl curl handle

No it doesn't. The API provides socket(s) or fd_sets, there's no limitation or
restriction in the API which says libcurl will only use one socket.

> so it would have to expose all the sockets of the dns resolution per handle
> to function properly, which seems not trivial.

Sorry, but I claim it already exposes "all the sockets of the dns resolution
per handle". See the lib/asyn-ares.c:Curl_resolver_getsock() funtion, which is
called from the multi_getsock() function which is used to figure out all the
sockets a particualr curl handle is using and what action to wait for on
those sockets.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-12-18