barbie has asked for the wisdom of the Perl Monks concerning the following question:
I have a bit of code, which talks to a server to retrieve some data from the server. In most cases this runs happily and returns the required data within the blink of an eye, the socket is closed and on to the next server. However, if the server is currently processing something else, which is taking some time to complete, although the connection is generated the data from the server is not sent for a very long time. As a consequence a timeout is required.
Unfortunately the system default timeout kicks in and prints "Alarm clock" and kills the script completely.
First we had:
my $sock = new IO::Socket::INET( PeerAddr => $addr, PeerPort => "poke($nPOKEPORT)", Proto => 'tcp', Timeout => $nPOKESERVERTIMEOUT );
which *should* use the Timeout, but doesn't.
Then we had:
sub timeout { $SIG{'ALRM'} = \&timeout;print "Socket Timeout\n"; } $SIG{'ALRM'} = \&timeout; eval { alarm($nPOKESERVERTIMEOUT + 1); while (my $line = <$sock>) { $data .= $line; } alarm 0; }
which had no effect at all.
I even changed the timeout function to:
sub timeout { die "Socket Timeout\n"; }
all to no avail.
There are typically 20-40 servers the script needs poll, and dying on the first one, just because that happens to busy isn't going down very well.
I have noted that there are similar problems recorded elsewhere on the interweb, but many seem to be regarding LWP or Database connections. This script does neither. I have also noted various references to the 'infamous "Alarm clock" problem', although I can't find any actual documentation regarding an actual '"Alarm Clock" problem'. There are a couple of liberal statements to upgrade your version of IO::Socket, but seeing as we are using the latest versions that doesn't really help. Anyone had expereince of this or know where I might be able to find a solution ?
Any thoughts and suggestions gladly accepted.
IO::Socket => 1.27
IO::Socket::INet => 1.26
Perl => 5.8.0
Linux => Red Hat 8.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Barbie
Birmingham Perl Mongers
Web Site: http://birmingham.pm.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket::INet and the Alarm Clock
by barbie (Deacon) on Jun 09, 2003 at 09:57 UTC |