cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: timeout issue while using POST messages over htttps (or http)

From: Sunny Khatri <sunny.kh03_at_gmail.com>
Date: Mon, 7 Oct 2013 10:58:01 -0700

CURLOPT_TIMEOUT is the time you allow a for a connection to be established
and transfer to be completed. A timeout can happen if the response from the
server is too large to be transferred back to the client in that timeout
window or if you have your timeout set to a low value.
Another thing to consider is whether server is sending any response or not
for those timed out requests.

Just my opinion, may be someone else has better idea.

Thanks
Sunny

On Mon, Oct 7, 2013 at 10:07 AM, Olivier Singla <olivier.singla_at_gmail.com>wrote:

> I am having some timeout issue using libcurl in C/C++.
>
> The device I am working on talks with a server, through a GSM modem, using
> POST messages over https (or http).
> This is always the device which initiate the communication with the
> server, by sending a POST message.
> Once the server receive the message, it will reply back with another
> message to the device.
> It might happen that the server has to delay replying to the device, but
> the delay will never exceed three minutes.
>
> What I am seeing:
> - once the GSM link is established (pppd), the server *always* receive the
> POST message sent by the device.
> - 'most of the time', the device receive the reply sent by the server,
> even if there is no delay in replying... But not always: in about 20 to 25%
> of the cases, the device do not receive the message back from the server,
> and times out.
>
> I have control on both sides (device and server).
> On the server side, I am using libmicrohttpd.
> When the device did not receive the reply back from the server, sending
> back the reply does not trigger any error or warning on the libmicrohttpd
> side...
>
> Here is a snapshot of the code I am using on the device side, using the
> latest libcurl (I simplified it);
>
> struct curl_httppost *formpost = NULL;
> struct curl_httppost *lastptr = NULL;
> struct curl_slist *headerlist = NULL;
>
> // Fill in the file upload field
> curl_formadd( &formpost,
> &lastptr,
> CURLFORM_COPYNAME, "request",
> CURLFORM_FILE, SERVER_REQUEST_XML,
> CURLFORM_END );
>
> // Fill in the filename field
> curl_formadd( &formpost,
> &lastptr,
> CURLFORM_COPYNAME, "filename",
> CURLFORM_COPYCONTENTS, "request.xml",
> CURLFORM_END );
>
> // Fill in the submit field too, even if this is rarely needed
> curl_formadd( &formpost,
> &lastptr,
> CURLFORM_COPYNAME, "submit",
> CURLFORM_COPYCONTENTS, "send",
> CURLFORM_END );
>
> CURLcode curl_code;
>
> headerlist = curl_slist_append( headerlist, "Expect:" );
> headerlist = curl_slist_append( headerlist, "Keep-Alive: 300" );
> headerlist = curl_slist_append( headerlist, "Cache-Control: max-age=0"
> );
> CURL_EASY_SETOP( curl, CURLOPT_HTTPHEADER, headerlist );
>
> CURL_EASY_SETOP( curl, CURLOPT_VERBOSE, 1L );
> CURL_EASY_SETOP( curl, CURLOPT_DEBUGFUNCTION, debug_function );
> CURL_EASY_SETOP( curl, CURLOPT_DEBUGDATA, curl_debug_fp );
> CURL_EASY_SETOP( curl, CURLOPT_READFUNCTION, read_callback );
>
> CURL_EASY_SETOP( curl, CURLOPT_POST, 1L );
> CURL_EASY_SETOP( curl, CURLOPT_HTTPPOST, formpost );
>
> CURL_EASY_SETOP( curl, CURLOPT_FOLLOWLOCATION, 1 ) ;
> CURL_EASY_SETOP( curl, CURLOPT_SSL_VERIFYPEER, 0L );
> CURL_EASY_SETOP( curl, CURLOPT_SSL_VERIFYHOST, 0L );
> CURL_EASY_SETOP( curl, CURLOPT_SSL_SESSIONID_CACHE, 0L );
>
> CURL_EASY_SETOP( curl, CURLOPT_WRITEDATA, (void *)fp_result );
> CURL_EASY_SETOP( curl, CURLOPT_WRITEFUNCTION, write_callback );
>
> CURL_EASY_SETOP( curl, CURLOPT_POSTFIELDSIZE, request_len );
>
> CURL_EASY_SETOP( curl, CURLOPT_DNS_CACHE_TIMEOUT, 30L );
> CURL_EASY_SETOP( curl, CURLOPT_TIMEOUT, timeout );
> CURL_EASY_SETOP( curl, CURLOPT_CONNECTTIMEOUT, 30L );
>
> CURL_EASY_SETOP( curl, CURLOPT_TCP_KEEPALIVE, 5L );
> CURL_EASY_SETOP( curl, CURLOPT_TCP_KEEPIDLE, 5L );
> CURL_EASY_SETOP( curl, CURLOPT_TCP_KEEPINTVL, 30L );
>
> CURL_EASY_SETOP( curl, CURLOPT_URL, url );
>
> CURLcode res = curl_easy_perform( curl );
>
> When the device misses the reply back from the server, it times out
> (CURLE_OPERATION_TIMEDOUT), and never receives the message.
> What I do not understand is that netstat shows the TCP connection
> established on both sides...
>
> If I do not setup a timeout, the device never receives the message and
> hangs forever, at least until the GSM link is cut off...
>
> Any idea what I am missing, or doing wrong ?
>
> Many TIA if somebody could point me in the right direction!
> Olivier
>
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-10-07