Subject: | Long running processes an alarm() |
I have a script that does thousands of whois lookups. I'm getting
'random' timeout errors.
I've tracked the problem down to line ~625 of Proxy.pm:
eval {
$SIG{ALRM} = sub { die 'timeout'; };
alarm(($timeout || $self->{master_timeout}) + 5);
$sock = IO::Socket::INET->new(
Proto => 'tcp',
PeerAddr => $serv || $self->{master_whois},
PeerPort => $port || $self->{master_port},
Timeout => $timeout || $self->{master_timeout}
) || die "Unable to create socket $!";
alarm(0);
};
alarm(0) doesn't get called if the socket creation fails. If connections
fail for $timeout seconds, $SIG{ALRM} is called outside of the eval block.
I fixed it by changing it to:
$SIG{ALRM} = sub { die 'timeout'; };
alarm(($timeout || $self->{master_timeout}) + 5);
eval {
$sock = IO::Socket::INET->new(
Proto => 'tcp',
PeerAddr => $serv || $self->{master_whois},
PeerPort => $port || $self->{master_port},
Timeout => $timeout || $self->{master_timeout}
) || die "Unable to create socket $!";
};
alarm(0);
So that alarm(0) is always called.