cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Timeouts and using CURLOPT_FRESH_CONNECT

From: Andrew Fuller <andrewfuller2k2_at_yahoo.co.uk>
Date: Thu, 27 Nov 2003 13:22:15 +0000 (GMT)

Hi,

Please find test application attached which shows the
behaviour described below. Also attached is the
output I receive, both with and without setting
FRESH_CONNECT.

The incorrect output shows how a second fetch to a
location which has just timed out returned the body
from the first fetch.

{
FYI, my app uses a publicly-viewable JSP at
http://www.mycgiserver.com/~fullerand/fetch.jsp which
allows you to specify the delay before a response is
generated, using the delay parameter (in ms), eg :

http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=1000
}

Thanks for looking at this,

rgds
Andrew Fuller

 --- Daniel Stenberg <daniel-curl_at_haxx.se> wrote: > On
Wed, 26 Nov 2003, Andrew Fuller wrote:
>
> > I just want to clarify the use of
> CURLOPT_FRESH_CONNECT because the docs say
> > only to use it if you know what it does, and I
> guess I don't :)
>
> ;-)
>
> > Suppose I use a curl handle to fetch a document
> which times out, for example
> > :
> >
> > Set CURLOPT_TIMEOUT to 5. Fetch
> http://domain.com/mypage.jsp?delay=10 (takes
> > 10s)
> >
> > After this times out, I want to use the same
> handle to fetch a document from
> > the same location, but with different params, eg :
> > http://domain.com/mypage.jsp?delay=3
> >
> > At present, the second fetch uses the connection
> from the first, and the
> > response I get back is from the first request.
>
> That sounds exactly like a bug description! Would
> you be able to provide us
> with the source of a program that repeats this
> problem on a public URL?
>
> When libcurl times out, it really must close the
> connection since it can't be
> re-used later without risking exactly what you
> describe.
>
> > To correct this, should I set
> CURLOPT_FRESH_CONNECT to 1 every time a fetch
> > times out? Does this only affect the next fetch?
>
> FRESH_CONNECT makes the new request not attempt to
> re-use an existing
> conection, so if you set that on your second request
> it should suffice as a
> work-around for this particular problem. But still,
> this problem is a bug that
> we should fix...
>
> --
> Daniel Stenberg -- http://curl.haxx.se/ --
> http://daniel.haxx.se/
> [[ Do not post private mails to this email address.
> They won't reach me. ]]
>
>
>
-------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback
> Program.
> Does SourceForge.net help you be more productive?
> Does it
> help you create better code? SHARE THE LOVE, and
> help us help
> YOU! Click Here: http://sourceforge.net/donate/
>

________________________________________________________________________
Download Yahoo! Messenger now for a chance to win Live At Knebworth DVDs
http://www.yahoo.co.uk/robbiewilliams

****** fetch1 : http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=2000...

* About to connect() to www.mycgiserver.com:80
* Connected to www.mycgiserver.com (212.69.162.53) port 80
> GET /~fullerand/fetch.jsp?delay=2000 HTTP/1.1
Host: www.mycgiserver.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

* Connection #0 left intact
Done. Return : 28

****** fetch2 : http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=10...

* About to connect() to www.mycgiserver.com:80
* Connected to www.mycgiserver.com (212.69.162.53) port 80
> GET /~fullerand/fetch.jsp?delay=10 HTTP/1.1
Host: www.mycgiserver.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

Param : delay has value : 10.* Closing connection #1
Done. Return : 0

Press any key to continue

****** fetch1 : http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=2000...

* About to connect() to www.mycgiserver.com:80
* Connected to www.mycgiserver.com (212.69.162.53) port 80
> GET /~fullerand/fetch.jsp?delay=2000 HTTP/1.1
Host: www.mycgiserver.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

* Connection #0 left intact
Done. Return : 28

****** fetch2 : http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=10...

* Re-using existing connection! (#0)
* Connected to [re-used] (212.69.162.53) port 80
> GET /~fullerand/fetch.jsp?delay=10 HTTP/1.1
Host: www.mycgiserver.com
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

Param : delay has value : 2000.* Closing connection #0
Done. Return : 0

Press any key to continue

// TestCurl2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <curl/curl.h>

int main(int argc, char* argv[])
{
        // set up
        CURL* pHandle = curl_easy_init();
        curl_easy_setopt(pHandle, CURLOPT_VERBOSE, 1);
        char* pszUrl1 = "http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=2000";
        char* pszUrl2 = "http://www.mycgiserver.com/~fullerand/fetch.jsp?delay=10";

        // FETCH 1 : want to force this to time out
        printf("****** fetch1 : %s...\n\n", pszUrl1);
        curl_easy_setopt(pHandle, CURLOPT_URL, pszUrl1);
        curl_easy_setopt(pHandle, CURLOPT_TIMEOUT, 1);
        CURLcode nRet = curl_easy_perform(pHandle);
        printf("Done. Return : %d\n\n\n", nRet);

        // make sure it timed out
        if(nRet != 28)
        {
                printf("Didn't time out -> invalid test\n");
                return 1;
        }

        // insert this line as a workaround to fix behaviour described below
        curl_easy_setopt(pHandle, CURLOPT_FRESH_CONNECT, 1);

        // FETCH 2: want this fetch to succeed
        // possible curl bug is that the returned body (to stdout)
        // is that from the previous fetch (the jsp returns the delay parameter in the body)
        printf("****** fetch2 : %s...\n\n", pszUrl2);
        curl_easy_setopt(pHandle, CURLOPT_URL, pszUrl2);
        curl_easy_setopt(pHandle, CURLOPT_TIMEOUT, 10);
        nRet = curl_easy_perform(pHandle);
        printf("Done. Return : %d\n\n\n", nRet);

        return 0;
}

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-27