curl-library
time-outs in multi interface gap with no socket
Date: Fri, 23 Mar 2018 09:34:06 +0100 (CET)
Hi,
If you're using libcurl's multi interface with a libcurl built to use the
threaded resolver backend, you have probably experienced that
curl_multi_fdset() may return without a socket during the name resolve phase.
It will also cause curl_multi_wait() to return instantly.
This behavior easily cause programs to busy-loop and spend 100% CPU for that
time period unless you've taken precautions to handle this properly. And how
to do it properly is not exactly crystal clear.
What's even worse is that curl_multi_timeout() doesn't help much and will not
offer a good timeout/sleep time to use so you basically need to make up some
logic of your own and probably exponentially back off while retrying
curl_multi_perform(). Users of the multi_socket API possibly have it even
messier.
It struck me when working on curl_multi_poll[1] (as a potentially new API
entry), that we should just make sure to set timeout times correctly during
this period so that the multi_socket API starts to work much better in this
gap, and it also provides applications a good time to wait until calling
perform again.
With this fixed, implementing curl_multi_poll() is ridiculously easy.
I'm pretty confident in this change and the PR is green so far. In a second
step, I intend to change the implementation of curl_easy_perform() to make use
of this approach, as it should simplify that code as well.
[1] = https://github.com/curl/curl/pull/2415
-- / daniel.haxx.se ------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.htmlReceived on 2018-03-23