Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket problems #1057

p5pRT opened this issue Jan 19, 2000 · 2 comments

Socket problems #1057

p5pRT opened this issue Jan 19, 2000 · 2 comments


Copy link

p5pRT commented Jan 19, 2000

Migrated from (status was 'resolved')

Searchable as RT2008$

Copy link

p5pRT commented Jan 19, 2000


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;

  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
  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(@​NoConnect,$Current) if($!=/Interrupted/i);
  push(@​Refused,$Current) if($!=
  print "Connection refused to $Current.\n"
  print "No connection to $Current.\n" if($!=

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

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@​
Sr Network Consultant Office​: (416)640-9426
NTG International Pager​: (416)608-5272

Copy link

p5pRT commented Nov 28, 2003

From The RT System itself

Signal handlers are documented to be unreliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant