cURL / Mailing Lists / curl-library / Single Mail


Re: Async cancel lengthy DNS lookup

From: Constantine Sapuntzakis <>
Date: Thu, 31 Dec 2009 13:00:31 -0800

On Wed, Dec 30, 2009 at 5:22 PM, Adrian Michel <> wrote:
> I implemented async cancel functionality by using the progress callback, but
> that doesn't seem to work during the DNS lookup phase. I tested with a
> domain name that doesn't resolve and I don't get any progress callback calls
> and have to wait until the curl_easy_perform returns with a failure result,
> which can take a while. This is unfortunate as since these are GUI apps, the
> user commands, including that to cancel a lengthy http request, must be very
> responsive.

DNS and cancellation is not a great story on Windows. Does anybody know if the
native Windows APIs support cancelling a DNS request?

Curl has three resolvers on Windows: c-ares, synchronous, and
threaded. Of those,
synchronous and threaded definitely do not support cancellation well.
(1) I'm not sure about
c-ares -- it should be possible to cancel a DNS request when using
curl multi interface by closing
the easy handle early. There may be easier ways... I don't use c-ares myself.

c-ares is good for Internet applications that do Internet DNS lookups.
It is not the best
solution for resolving intranet names - it doesn't support non-fully
qualified domain names
well on Windows. Nor does it follow WIndows' complex DNS resolution
rules. Nor does it
support Windows 7's Direct Connect or NetBIOS.

Barring a good implementation of cancellation, I would say do the HTTP
request in a thread that
can be "abandoned". Probably a good idea to bound the number of
abandoned threads at something like 10.
This allows the user to recover from a couple bad requests while
bounding the amount of system resources taken.
Of course, an insistent user could still exhaust all 10 threads and
then you revert to an unfriendlier behavior of
blocking new HTTP requests until one of the threads exits.


(1) In fact, the current threaded implementation calls TerminateThread
in certain conditions which can leave the process in a bad state.
There is a patch in the queue to clean up this and other issues with
the Windows thread implementation.
List admin:
Received on 2009-12-31