Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.88k stars 530 forks source link

Socket problems #1057

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

Migrated from rt.perl.org#2008 (status was 'resolved')

Searchable as RT2008$

p5pRT commented 24 years ago

From JeffBreukelman@metronet.ca

I have written a script that uses Perl sockets to connect to a series of routers. The script uses a SIGALRM function to close the connection if it hasn't logged in or transmitted data after 30 seconds. The SIGALRM function always works\, but on occasion the socket() function causes a segmentation fault on the next attempt to connect to a router. This always occurs after the SIGALRM function closes the connection\, but not every time. It seems to occur most often if the connection that was closed had gotten stuck in an infinite loop. However\, I have seen it occur when the previous connection was simply stuck waiting for input.

I am running Perl version 5.004_04 on Linux. The code for the SIGALRM function is as follows;

sub SigALRMHandler{   print "Got SIGALRM - closing socket.\n" if($Debug>=3);   close(S) || print "Error closing socket\n";   }

and the code where the error occurs is as follows;

while($#Routers>=0){   $Current=shift(@​Routers);   $RawIP=pack('C4'\,split(/\./\,$Current));   $Remote=pack($SockAddr\,$AF_INET\,$Port\,$RawIP);   alarm 30;   print "Getting socket and connecting to $Current.\n" if($Debug>=2);   print "$#Routers left in queue.\n" if($Debug>=2);   shutdown(S\, 2); # Close old sockets - might be causing problems   print "Getting socket.\n" if($Debug>=4);   socket(S\,$AF_INET\,$SOCK_STREAM\,$Proto) || die("Socket Error​: $!\n");   print "Binding socket.\n" if($Debug>=4);   bind(S\,$Local) || die("Bind Error​: $!\n");   print "Connecting to $Current.\n" if($Debug>=4);   connect(S\,$Remote) || do{   push(@​CErr\,$Current);   push(@​NoConnect\,$Current) if($!=~/Interrupted/i);   push(@​Refused\,$Current) if($!=~/refused/i);   print "Connection refused to $Current.\n" if($!=~/refused/i);   print "No connection to $Current.\n" if($!=~/interrupted/i);   next;   };

When Perl crashes it always does so while running the socket() function above.

Can you tell me what's going on here?

Jeff Breukelman.

"If you're going to do it\, do it right. If you're not going to do it right\, don't do it." -me Jeff Breukelman jeff@​ntgi.net Sr Network Consultant Office​: (416)640-9426 NTG International Pager​: (416)608-5272

p5pRT commented 20 years ago

From The RT System itself

Signal handlers are documented to be unreliable.