cURL / Mailing Lists / curl-library / Single Mail


Re: Infinite loop in Curl_splay

From: Christian Hägele <>
Date: Fri, 1 Jul 2011 13:38:03 +0000 (UTC)

Daniel Stenberg <daniel <at>> writes:

>> I am still fighting this problem. I still can't reproduce this issue, but
>> while debugging my code I found that I call curl_multi_add_handle within the
>> curl_multi_socket_action function (on the same multi-handle). That's because
>> I call some subsequent functions within the CURLOPT_WRITEFUNCTION callback.
>> Is this safe to do or can that produce this infinite loop?
> I'm not sure - but I would certainly suspect it may cause problems, and yes it
> sounds like a plausible explanation.
> We should figure it out for sure and add something about it to the
> documentation!

After I changed my code so that curl_multi_add_handle is not called from within
curl_multi_socket_action the infinite loop did not occur again.
I didn't debug through the code in detail but adding a easy-handle to a multi-
handle inserts a new timeout in the splay-tree and might change its internal
structure while the same thread on another (lower) frame in the callstack is
currently traversing it. (Again I did not reproduce it on intention yet)

This can be a pitfall for many developers, because it seems to work nice most of
the time and only in very rare special cases causes a problem.
Some hint in the documentation would be nice and better handling within curl
would be even nicer.

List admin:
Received on 2011-07-01