develooper Front page | perl.libwww | Postings from February 2001

libwww and setting a timeout

Thread Previous
From:
Thomas Tatum
Date:
February 13, 2001 13:49
Subject:
libwww and setting a timeout
Message ID:
KGEEINJAHANAFKAILLGMCEKNFJAA.thomas@koz.com

My name is Thomas Tatum and I am new to this mailing list (hello! - first
time poster)

I feel there is still an outstanding timeout bug in the libwww library that
needs addressing.  I think it has been brought up before on the mailing list
but from the uci archives, dejanews, and the latest FAQ
(http://people.we.mediaone.net/kfrankel/lwpfaq.txt q19 and 20), I have not
seen a solution.

The bug is that on certain web sites the alarm or callback solution(from
FAQ) will NOT stop the request from trying to connect after X seconds.  Its
a hard one to track down because the behavior is non-repeating.

(perl 5.005_03 (sun4-solaris)
IO 1.20
LWP 5.47)

Below is a script(uses the alarm technique) I run from my Unix shell and
feed a URL(with -c) to test the timeout bug.  The script merely returns the
start time and end time of the request.  It uses a 20 second alarm and will
print TIMED OUT if the alarm goes off.

I have no solution to offer to the list, but I do have a few clues:

Clue 1) I have a site that almost daily gets "hung-up" into a state where it
doesnt respond to a normal browser pull dependably.  I pass the URL to the
below script and will get a response from the site in an undeterministic
amount of time(usually greater than the 20 second alarm).  When I run the
script under the debugger however, the alarms work as they were designed.
(To double check the bug, I would immediately re-run the script outside of
the debugger and it would return in an underministic amount of time)

Clue 2) I have been to www.perl.org a few times in the last few days where
it seemed to be "hung-up" and I tested my script on that URL. The alarms
would break out of the request fine in 20 seconds, but not print the
statement in the if$@ block.  I ran this script around 10 times and one of
the times the alarm didnt break out at all.  I tried it once in the debugger
and it worked as intended (broke out after 20 seconds and printed the TIME
OUT message)

I have a few web sites that get "hung-up" into a state where I can get the
bug to occur on a daily basis.  If someone on the development team is
willing to do a trace/de-bug of this problem, I can call/email the URL of
the site when this happens.

Thanks in advance for the help.

Thomas

=============================
#!/usr/local/bin/perl -w

use LWP::Simple;
use Getopt::Std;
require LWP::UserAgent;

  if ((!(getopts('hc:'))) || (!($opt_c))  || ($opt_h)) {

        usage();

  }


$URL = $opt_c;

print "\n\tWill retrieve $URL\n\nTime is ". localtime(time) . "\n\n";

	$ua = LWP::UserAgent->new;
	$request = HTTP::Request->new('GET',$URL);

	eval{
	  local $SIG{ALRM} = sub { die "timeout"; };
	  alarm(20);

	  $response = $ua->request($request);
	  $content = $response->content;

	  alarm(0);
	};

if ($@ =~ /timeout/) {
  print "TIMED OUT after alarm\n\n";
}

print "Done:\n  Time is ". localtime(time). "\n\n";
print "content is $content\n";

sub usage
  {print "\nUsage:\n\t$0 {-h} -c url to pass to lwp check"; }



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About