cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Strange timeout on win32, all the bytes received but library waiting for -1

From: Marius Seritan <mseritan_at_jacent.com>
Date: Tue, 23 Jul 2002 10:27:23 -0700

As usually, it just takes one bug report to the world before you can leap ahead on your bug resolution :-(

I was able to duplicate the problem reported below issue with logging on and it is related to a clash between 2 successive transfers on the http/1.1 persistent socket. The big problem (in the app and/or tomcat level) is that tomcat replies with a header AND a body to a HEAD request :-( After this mishap tomcat closes the socket, however curl may already be started on the next http POST. Curl will interpret the body of the previous HEAD as a post and hang.

1. curl sends the headerer for the HEAD
2. tomcat replies with the HEAD header
3. curl returns to the app
4. the app requests a POST with no parameters
5. curl sends the POST header
6. tomcat mistakenly sends the HEAD reply body
7. curl interprets the body as the header
8. curl defaults to a content-length of -1
9. curl waits for the timeout period to get exactly -1 bytes.

I am not sure I got all the details right on the race condition, however one way or the other I need to address it in the app. It will surely be nice if curl could bail out faster instead of waiting for -1 bytes

----- Original Message -----
From: "Marius Seritan" <mseritan_at_jacent.com>
To: <curl-users_at_lists.sourceforge.net>
Sent: Tuesday, July 23, 2002 9:12 AM
Subject: Strange timeout on win32, all the bytes received but library waiting for -1

> Hi,
>
> I am trying to use libcurl in one of our projects. Many thanks to the
> curl community for such a great product!
>
> Most of the transfers occur just fine however after some 20-50 downloads
> the library may get in this state where it hangs for (literally) 600sec.
> I set the timeout to 20sec reducing the hang period to that, however I
> get the following error: Operation timed out with 2508 out of -1 bytes
> received. The error was probably occuring without the shorter timeout I
> did not pay attention to that case. The number of bytes received matches
> the size of the document I am trying to download. The timeout occurs on
> various documents.
>
> Of course when I turn on debugging this problem goes away. It looks like
> there is some problem decoding content-length or similar. Any pointers?
>
> More details:
> I am using curl-7.9.8 on win32. My application is multithreaded however
> a specific curl thread is accessed from just one thread. I implemented
> my own function to write the result to a file. I am using transfers from
> specified IP addresses or localhost, I do not need to do DNS lookups. I
> am downloading from a tomcat server and I requested HTTP/1.1, at least
> the transfers I debugged are re-using the existing socket. Although the
> application is multithreaded this problem occurs even with just one
> thread active - the other threads hold curl handles but do not perform
> any operation on them.
>
>
> Thanks,
>
> Marius
>
> ------- typical API usage, error checking removed ---------------
> m_hCurl = curl_easy_init();
> rc = curl_easy_setopt(m_hCurl, CURLOPT_WRITEFUNCTION, CurlWriteFunction
> );
> rc = curl_easy_setopt(m_hCurl, CURLOPT_HEADERFUNCTION,
> CurlHeaderFunction );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_FAILONERROR, 1 );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_NOPROGRESS, 1 );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_COOKIEJAR, "-" );
> rc = curl_easy_setopt(m_hCurl, CURLOPT_VERBOSE, 1 );
> rc = curl_easy_setopt(m_hCurl, CURLOPT_DEBUGFUNCTION, CurlDebugCallback
> );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_NOBODY, 0 );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_POSTFIELDS, pszPostData );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_POSTFIELDSIZE, uPostSize );
> rc = curl_easy_setopt(m_hCurl, CURLOPT_FILE, out );
> char errBuffer[CURL_ERROR_SIZE]; errBuffer[0] = 0;
> rc = curl_easy_setopt( m_hCurl, CURLOPT_ERRORBUFFER, errBuffer );
>
> rc = curl_easy_setopt( m_hCurl, CURLOPT_FILETIME, 1 );
> rc = curl_easy_setopt( m_hCurl, CURLOPT_TIMEOUT, 20 );
>
> rc = curl_easy_setopt( m_hCurl, CURLOPT_WRITEHEADER, &headers );
>
> int rcDownload = curl_easy_perform(m_hCurl);
> if( rcDownload != 0 ) {
> printf( errBuffer);
> }
>
> rc = curl_easy_setopt( m_hCurl, CURLOPT_WRITEHEADER, NULL );
>
> rc = curl_easy_setopt( m_hCurl, CURLOPT_ERRORBUFFER, NULL );
>
> rc = curl_easy_getinfo( m_hCurl, CURLINFO_FILETIME, plDocumentTime );
>
> {
> long lSize=0,lHttpCode=0;
> double fConnectTime=0, fTotalTime=0;
> curl_easy_getinfo( m_hCurl, CURLINFO_TOTAL_TIME, &fTotalTime );
> curl_easy_getinfo( m_hCurl, CURLINFO_CONNECT_TIME, &fConnectTime );
> curl_easy_getinfo( m_hCurl, CURLINFO_SIZE_DOWNLOAD, &lSize );
> curl_easy_getinfo( m_hCurl, CURLINFO_HTTP_CODE, &lHttpCode );
> printf( "Exiting curl_easy_perform code %d, bytes %d, connect time %f,
> xfer time %f\r\n", lHttpCode, lSize, fConnectTime, fTotalTime );
> }
>
>
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÓ†+,ù޵隊X¬²š'²ŠÞu¼ÿN§gž‘g¥r‰ž¶ˆzH^j÷§þm§ÿÿ¶§’ž“÷(›û
Received on 2002-07-23