Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL: idle timeout interval more than specified value

I am using libcurl to create an http connection to a server. During initialization I have specified an idle timeout value of 5 seconds and also specified as progress callback function. I was expecting cURL to abort the connection after 5 seconds of inactivity and to stop calling the progress callback but I found that curl times out after around 15 seconds. Why is curl taking more time to timeout than I what I have specified? Setting timeout to a larger value does not help. If I specify 100 secs, it timesout after 105 secs of inactivity.

code = s_curl_easy_setopt(m_curl_handle, CURLOPT_NOPROGRESS, 0);
assert(code == CURLE_OK);
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
assert(code == CURLE_OK);

EDIT: The timeout code

//this will set the timeout for quitting in case the network goes down
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_LOW_SPEED_LIMIT, 1);
code = s_curl_easy_setopt(m_curl_handle, CURLOPT_LOW_SPEED_TIME, m_idle_timeout);
like image 680
341008 Avatar asked Nov 12 '10 12:11

341008


People also ask

How do I increase my curl timeout limit?

To set a timeout for a Curl command, you can use the --connect-timeout parameter to set the maximum time in seconds that you allow Curl to connect to the server, or the --max-time (or -m) parameter for the total time in seconds that you authorize the whole operation.

How do I check my curl timeout?

Tell curl with -m / --max-time the maximum time, in seconds, that you allow the command line to spend before curl exits with a timeout error code (28). When the set time has elapsed, curl will exit no matter what is going on at that moment—including if it is transferring data. It really is the maximum time allowed.

Does Curl have a timeout?

The Curl timeout parameter specifies (in seconds) the maximum duration needed for a file/data transfer operation. It is an effective parameter when dealing with issues like links going down or slow networks. This parameter can also take a decimal point value.


1 Answers

I have figured this one out. cURL updates its progress approximately one per second. To calculate idle timeout cURL calculates the average bytes/sec over 6 updates and compares it with the CURLOPT_LOW_SPEED_LIMIT. If this value is less than CURLOPT_LOW_SPEED_LIMIT for more than CURLOPT_LOW_SPEED_TIME seconds at a stretch, it times out. So if the CURLOPT_LOW_SPEED_TIME is 5 seconds, cURL will calculate the average bytes/sec over the last 6 progress updates (approx 5 secs) and then check if it is less than CURLOPT_LOW_SPEED_LIMIT for at least 5 seconds, thus taking total time of approx. 10 seconds.

like image 150
341008 Avatar answered Sep 20 '22 18:09

341008