cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: cURL cygwin and gethostbyname threading problems

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 8 Feb 2002 08:52:50 +0100 (MET)

On Thu, 7 Feb 2002, Kord Campbell wrote:

> Our crawler uses the cURL libraries, and we've been working on getting it
> running in cygwin for the past few weeks. We have (apparently) run into a
> problem with the gethostbyname calls that cURL uses.

I'll try to reply with information about curl stuff, more genericly.
Unfortunately, I don't have any detailed insights in the dungeons of cygwin
internals.

> When running the crawler with more than one thread, and after a bit of time
> passes, the crawler will crash inside the cURL routines, right where cURL
> accesses the gethostbyname funtion.
>
> As we understand it, cygwin does not offer a reentrant version of
> gethostbyname (gethostbyname_r coming to mind), and as such may be
> susceptible to errors when used with multiple threads. This also apparently
> breaks the reentrant capabilities of cURL libraries themselves, when
> compiled and used under cygwin.

If that is indeed the case, then yes, libcurl will not be working fully
re-entrant.

> The nut of our question is whether anyone else can confirm or deny any
> problems with the gethostbyname function in cygwin, using cURL

I would recommend you to take this question to a cygwin forum where people
with knowledge about internals like this might be likely to hang out.

I am also interested in getting to know if this truly is the case or not.

> and if confirmed, what was done to work around this problem?

Unregarding of what operating system you use, this could happen. (I here
assume that your program is at least somewhat portable.) Not all operating
systems provide thread-safe versions of the name resolving functions.

What to do? Well, if you can't avoid using libcurl from several simultanous
threads you need to protect the name resolving function with a mutex or
something, so that only one function call will be used at any given moment.
Those thread synchronising mechanisms aren't very portable either though.

To make things even worse, it is next to impossible for a configure script or
similar to actually find out if a platform has a thread-safe gethostbyname()
or not, since several platforms these days actually have a gethostbyname()
function (and not gethostbyname_r()) that works in a thread-safe manner!

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2002-02-08