Perl 5.003.03: race condition in t/lib/io_sock.t
authorLupe Christoph <lupe@alanya.m.isar.de>
Wed, 4 Sep 1996 02:54:41 +0000 (02:54 +0000)
committerAndy Dougherty <doughera@lafcol.lafayette.edu>
Wed, 4 Sep 1996 02:54:41 +0000 (02:54 +0000)
io_sock.t works by forking a subprocess it can communicate with.
It has the subprocess wait for the main process by sleeping 10
seconds or until an alarm arrives.

With my setup, the alarm signal arrives *before* the child
has a chance to ignore the alarm signal.

I fixed this by moving the "$SIG{ALRM} = sub {};" up before the
fork. It does not hurt to have the parent ignore alarms, too.

t/lib/io_sock.t

index e888c5e..53690b1 100755 (executable)
@@ -18,6 +18,7 @@ print "1..5\n";
 use IO::Socket;
 
 $port = 4002 + int(rand(time) & 0xff);
+$SIG{ALRM} = sub {};
 
 $pid =  fork();
 
@@ -51,7 +52,6 @@ if($pid) {
     # Wait for a small pause, so that we can ensure the listen socket is setup
     # the parent will awake us with a SIGALRM
 
-    $SIG{ALRM} = sub {};
     sleep(10);
 
     $sock = IO::Socket::INET->new(PeerPort => $port,