MonkeyMonk has asked for the wisdom of the Perl Monks concerning the following question:
> perl -v 5.8.4
Dear monks, On a production system where updates to Perl versions are not possible, I came across this SIG{ALRM} robber. Yes, dear monks, LWP stands accused. My question: can I go to bed with this robber?
Consider this code:eval { local $SIG{ALRM} = sub { die "Network Timeout/Error\n" }; alarm($maxNetworkDelay); $ip=URL_encode($ip); $encodedMAC=URL_encode($mac); my $macr="https://somescript/login; $request = HTTP::Request->new(GET => $macr); $ua = LWP::UserAgent->new( timeout => $maxNetworkDelay ); $response = $ua->request($request); $respcon = $response->content; alarm(0); }; <strike> if($@){ ilog("Network Delay/Error for ."); return (-1); }# </strike> if($response->status_line =~ /^500/ ){ ilog("Network Delay/Error for ."); return (-1); }
I have read whatever there is publicly and from what I understood, decided to write the above since DNS errors/network latency/wrong domain name are _ALL_ trapped by the above code.
As you can see, when using eval with LWP, _your_ error catching mechanism ( the parts struck out ) will not work since LWP internally has a mechanism of its own. What we can test, however is whether LWP has caught the alarm I have triggered.
I am seeking to understand the what is going on. The above code works all the time to satisfaction. My questions are:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: The curious case of LWP - the SIG{ALRM} robber
by ikegami (Patriarch) on Jul 05, 2010 at 18:04 UTC | |
|
Re: The curious case of LWP - the SIG{ALRM} robber
by Khen1950fx (Canon) on Jul 06, 2010 at 00:22 UTC | |
by MonkeyMonk (Sexton) on Jul 07, 2010 at 10:07 UTC |