cURL / Mailing Lists / curl-library / Single Mail


Re: Curl_multi_perform goes into infinite loop

From: Daniel Stenberg <>
Date: Thu, 28 Jul 2011 19:53:30 +0200 (CEST)

On Thu, 28 Jul 2011, ajil koshy wrote:

> I have an https client using libcurl (with openssl) multi APIs.
> Occasionally, I see that if remote peer application exits, the libcurl
> client's 'multi-loop' (the one which calls curl_multi_perform repeatedly
> till running handles reach zero) goes into an infinite loop instead of
> breaking out. Is this expected behavior?

Without any kind of timeout set, I figure there's a risk that something stalls
for what may be perceived as "infinitely".

But also note that you didn't state what libcurl version or OS you're using.

> Also, after each curl_multi_perform call, I also check if any errors
> occurred on the individual transfers using curl_multi_info_read function in
> which case I can exit the loop. I would like to know what is the definitive
> way to find out if remote peer has disconnected (and thereby error out of
> the multi-loop) while using libcurl?

curl_multi_info_read() is the definitive way.

> I have come across articles which suggest we can attempt to read from the
> socket which would but I am not sure of implications of doing this while
> using libcurl.

That's a really bad iadea. If you would read from a socket that is still in
use by libcurl then you will effectively ruin that transfer. Not to mention
that you would have to make an effort to even get to know the socket in tthe
first place.

> Is there any callback I can register for or info I can query in libcurl to
> achieve this?

You don't need any callback for that, curl_multi_info_read() is all you need.

List admin:
Received on 2011-07-28