and even wrapping an eval/ALRM around it fails to the tune of 50%.
About alarm()...
On Win32, alarm() is considered unsupported (man perlport). On Unices, alarm is affected by the signal handling API. The first standard one is unsafe (race condition, need to set the signal handler in the handler code, etc). The second one (POSIX) is safer and well-defined (sigaction). Try replacing this
> local $SIG{ALRM} = sub { die "alarm timeout" };
with something like this
sigaction SIGALRM,
new POSIX::SigAction( sub { die "alarm timeout" } )
or die "Error setting SIGALRM handler: $!\n";The signal handling model in Perl itself has changed from unsafe to safer (Perl 5.8). But the safer one can take longuer (no signal handling between Perl's internal "op-code"). I think there's a env var to force Perl using old model, starting with Perl 5.8.1 (cant remember its name).
See man perlipc(1) for more details and comments about timeout, sigaction, model, gethostbyname, etc
eval {
local $SIG{ALRM} = sub { die "alarm timeout" };
alarm($timeout);
$res = $ua->get($np_key_url);
alarm(0);
};
alarm(0);
What's the purpose of last alarm(0) ? Just becoming paranoid ? ;-) A more classical line replacing that call would be like if ($@ and $@ !~ /alarm timeout/) { die "oops time out"}
A possible problem is that there is only one ALRM signal handler at a time, by process. So using several handlers can lead to strange behaviour. Ex if a "eval/alarm" is used around LWP calls and LWP also uses a "eval/alarm". I guess LWP catches ALRM to set a 500 return code.
> Does this sound like an issue with LWP, IO:Socket, perl,
It's an issue with DNS timeout in IO::Socket::INET, apparently. I saw this when trying to reach down servers or inexistant ones. Perhaps the system dns lookup uses its own signal handler, -- I remember 'strace' showed me a EINTR in the last syscalls. Gisle's idea to use 'strace -tt' can be more informative to you.
LWP::UserAgent uses IO::Socket::INET, and the timeout handling code is different following what versions you use. With LWP 5.69, Perl 5.8.0 (Linux 2.4.18) the whole code is commented out, and the workaround seems to use your own signal handling around LWP calls (sigaction prefered). Seems to work for me. With LWP 5.43, Perl 5.005_03 (Linux 2.2.16) the code is there, and (dns) timeout cant be avoided easyly
All this seems quite complex, but hope this helps. It's not always easy to put together relevant informations in a 'big picture'.
Christophe
