简体   繁体   中英

Simple Perl socket script hanging

I have a Perl script consisting of the following:

 #!/usr/bin/perl
 # Script name: socket.pl

 # Build socket:
 use IO::Socket;
 my $sock = new IO::Socket::INET (
                                  PeerAddr => '74.74.74.74',
                                  PeerPort => '1543',
                                  Proto => 'tcp',
                                 )
 or die "Could not create socket: $@\n"; 

 # Make a pipe-delimited string out of the four arguments:
 $data = "$ARGV[0]$ARGV[1]|$ARGV[2]|$ARGV[3]|$ARGV[4]";

 # Write to socket and immediately close:
 print $sock "$data";
 close($sock);

The problem starts to surface when the script gets called many times. In a scenario where the script is getting called 60 times per minute, if I pgrep for socket.pl , I see 100 or 200 instances that have been "running" for up to 3 or 4 minutes. The server to which they are writing appears to receive $data immediately and on an exception free socket.

Given that I don't see any ostensible errors on the peer, why is this script lingering around even though it appears to have written to the socket? Could the interpreter be bogging down or hitting some constraint or limit (the script is running on a very capable box so its not system limitations)?

Thanks.

Not sure if this will help, but you could try closing the socket using the IO::Socket::INET itself: $sock->close() or $sock->shutdown(2) . Also try adding exit(0) at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM