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/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


In reply to IO::Socket::INet and the Alarm Clock by barbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.