cURL / Mailing Lists / curl-library / Single Mail

curl-library

Curl, threading and gethostbyname

From: Christian Mauduit <ufoot_at_ufoot.org>
Date: Thu, 26 Aug 2010 22:13:44 +0200 (CEST)

Hi,

I'm currently developping a program that uses Curl to support HTTP client
protocol but also uses raw sockets and the famously non-reentrant
gethostbyname.

I have a mutex for my own calls gethostbyname (so that my program
serializes its calls to it, for various reasons I prefer this than using
gethostbyname_r which, among other things, isn't portable) and things went
fine first but then I had errors with core dumps and things like:

"0x0077502f in Curl_getaddrinfo_ex () from /usr/lib/libcurl.so.4"

I really suspect calls to gethostbyname to be the problem, so my first
guess was "hey, libCurl might use gethostbyname too, and my mutex does not
take this in account". So I used the same mutex so that my program never
does, at the same time, a gethostbyname on its own and a libCurl call.

Still, bug continues to show :( So I'm asking myself if the problem could
be that libCurl calls gethostbyname or such function in a separate thread.
Does that make sense? Not sure, I lock all Curl calls with my mutex.

Finally, I tried to use:
"curl_easy_setopt (curl_handle, CURLOPT_NOSIGNAL, 1);"
since I read it could help multithreaded UNIX applications (my case).

So far I didn't reproduce the problem with CURLOPT_NOSIGNAL set, but I'd
really appreciate to have some expert advice on wether this has a chance
to be the solution, experience shows threading bugs are a pain in the b*tt
to track and I could run my program for hours while bug would be still
there.

The complete code is fairly big (available here:
http://www.ufoot.org/liquidwar/v6/snapshots/ ), so I extracted the
"interesting" parts, that is the libCurl code and my own call to
gethostbyname.

This being said, thanks for this great library, this problem excluded, it
works like a charm, found out how to use it in minutes. I also use the
command line at work since... a very long time, it rocks!

Have a nice day,

Christian.

-- 
Christian Mauduit <ufoot@ufoot.org> - http://deca.ufoot.org ___ __/\__
Liquid War 6 - http://www.gnu.org/software/liquidwar6      / _")\~ \~/
"Les amis de la vérité sont ceux qui la cherchent et non _/ /   /_ o_\
ceux qui se vantent de l'avoir trouvée" - Condorcet     (__/      \/



-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html

Received on 2010-08-26