cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Infinite loop when calling curl_multi_cleanup

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 18 Oct 2016 23:19:01 -0400

On 10/18/2016 7:16 PM, Miloš Ljumović wrote:
> "Handles. You must never share the same handle in multiple threads.
> You can pass the handles around among threads, but you must never use
> a single handle from more than one thread at any given time."
> I'm not sharing handles. Take a look at ServerProc. That's the thread
> responsible for multi_* interface. It's the only thread operating on
> hMultiHandle without protection. While other threads that uses
> PushRequest are locking the section where they use hMultiHandle. If
> libcurl is thread safe then my concept is fine.
>
> "Also, I notice you didn't give your curl_version() information.
> libcurl is continuously improving, and so is nghttp2. I would try the
> latest of both."
>
> 7.51.0 - DEV
> openssl - 1.0.2h
> nghttp2 1.15.0
>
> As I said - I have no problems. Program is working fine. After I added
> "connclose" in close_all_connections as suggested at the begging of
> this email chain - everything worked fine.
>
> Though I was worried that maybe I haven't implemented:
> multi_perform
> multi_wait
> multi_read
>
> in a way they were intended. That's all.
> Try the program (in the attachment) and we'll continue discussion.

I don't have Apple APNs to try this program. I reiterate that it appears
you are locking around adding and removing from the multi handle, but
not the other calls that use that handle. Any action on a handle is use
of a handle. "you must never use a single handle from more than one
thread at any given time."

Concerning your use of curl_multi_wait:

"If no extra file descriptors are provided and libcurl has no file
descriptor to offer to wait for, this function will return immediately." [1]

So if that happens it's not going to wait up to the 100ms you set. The
'EXAMPLE' section of that document shows how it's typically handled: If
numfds is 0 two or more times in a row then sleep 100 milliseconds.

Another thing is long options you are setting to 0 instead set to 0L.
Although in Windows either will work since sizeof(int)==sizeof(long)
it's not good practice in c variable argument functions (like
curl_easy_setopt) to pass a type different from what the option/format
specifies.

[1]: https://curl.haxx.se/libcurl/c/curl_multi_wait.html

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-10-19