Re: Timeout not working like I would expect

Gisle Aas (gisle@aas.no)
18 Feb 1999 14:13:28 +0100


Bob Reveal <breveal@c2o.com> writes:

> I have run into the following situation that I believe to be an anomaly
> with LWP.  I am setting timeout to be 30 seconds for a URL.  The URL is
> pointing at a 10 Mbyte file which takes some time to download.  Normally
> it downloads in about 15 seconds.  However, I have seen the download
> peak at 120 seconds.  When the download exceeds 30 seconds, the LWP
> timeout does not work the way I would expect.  I would expect the
> timeout logic to kick in when the elapsed time of the HTTP GET exceeds
> the 30 second timeout parameter.  When the initial connection is made
> within the timeout parameter and successive reads from the server are
> within the timeout window, LWP misses the timeout.  I wrote the
> following cgi to test out this scenario.  LWP does not catch this
> timeout scenario where the download will take ~600 seconds.  Any
> thoughts?

The current LWP timeout should only trigger if no activity is seen on
the connection to the server for the given period of time.  This fact
might need better documentation.  But perhaps we should also have an
absolute_timeout() attribute that does what you want.

You can achieve what you are after by setting up a request callback
and then die in the callback if it is too late.  Something like this
(untested):


  $ua->timeout(30);
  my $start = time;
  my $res = $ua->request(HTTP::Request->new(GET => "http://something"),
		         sub {
			     my($data, $response) = @_;
                             $response->add_content($data);
                             die "ABS-Timeout" if (time - $start) > 30;
                         }
	                );
  print $res->as_string;


Regards,
Gisle