I have a subroutine that is for timing out a traceroute attempt to a host. The routine is called like this, get_traceroute( 'microsoft.com' ).
For some hosts that often hang indefinately on the last hop to the host, I've implemented a timeout in the subroutine to stop the traceroute call after 10 seconds. However I am still seeing a LONG period of hanging for some hosts that is happening AFTER the timeout is reached, and when the subroutine is trying to CLOSE the pipe.
Why is this? By code is below
sub get_traceroute() { my $hostname = $_[0]; my $buf = ''; if( open my $pipe, "traceroute -I -n $hostname |" ) { my $start = [gettimeofday]; while(1) { my $vin = ''; vec($vin, fileno($pipe), 1 ) = 1; if( select($vin,undef,undef,1) ) { sysread $pipe, $buf, 2048, length $buf or last; } last if tv_interval($start, [gettimeofday]) >= 2; } close $pipe; } return $buf; }
UPDATE:
Talking with tye he's pointed out that close() does a wait() which is still waiting for the traceroute child to end. The best way, since I don't need any further output from the traceroute, is to kill the process. Open() returns the process id, so I can easily kill the traceroute.
In reply to Timing out a traceroute by vancetech
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |