cURL / Mailing Lists / curl-library / Single Mail

curl-library

Race condition in win32 gethostbyname_thread ?

From: Christian Buchner <christian.buchner_at_gmail.com>
Date: Sat, 2 Feb 2008 01:18:42 +0100

Hi,

I have a single threaded win32 application performing about 20 simultaenous
HTTP requests to servers with the
curl multi interface. It will access several servers at once (by means load
balancing through different subdomains),
sometimes requiring multiple host name resolutions at about the same time.

I recently upgraded to curl-7.18.0 and encountered a crash in module
llist.cin the function Curl_llist_insert_next()
The argument e passed to the function was NULL and the statement ne->next =
e->next caused an invalid
memory access.

The call stack in actual order is:

gethostbyname_thread
Curl_addrinfo4_callback
addrinfo4_callback
Curl_cache_addr
Curl_hash_add
Curl_llist_insert

I suspect a race condition among multiple resolver callbacks happening in
rapid succession, because when
I set the program counter (PC) into the calling function and re-executed the
Curl_llist_insert_next() function
call, the variable passed to the function was no longer NULL and no crash
occured on the second attempt.

Adding mutexes for protecting these lists while the callback accesses them
might therefore prevent a crash.

I will try witching to the non-threaded and synchronous gethostbyname()
resolver until this issue is fixed
in libcurl.

I have a PNG screenshot of the debug session showing the code line that
crashed and the call stack.
On request I can E-mail it to anyone interested.

If anyone cares what my programming project is about. It brings satellite
map data into the well known
M$ Flight simulator in realtime: Download and display during flight - My
project is under GPL license
even. Screenshots here:
http://forums.avsim.net/dcboard.php?az=show_topic&forum=147&topic_id=269083&mesg_id=269083&page=
You can add it to the list of cool projects that make use of curl.

Thanks to everyone involved in the curl project for making such a useful
library.

Christian Buchner
Received on 2008-02-02