Skip to content
Browse files

add alarm() around waitpid() per RT 79776; release 0.15

  • Loading branch information...
1 parent 842afe6 commit 7830a113f7619bafff3396a4d09d7b47e7307c06 @karpet committed
Showing with 31 additions and 2 deletions.
  1. +4 −0 Changes
  2. +25 −2 lib/Net/LDAP/Server/Test.pm
  3. +2 −0 t/01-ldap.t
View
4 Changes
@@ -59,3 +59,7 @@ Revision history for Net-LDAP-Server-Test
0.14 27 July 2012
* RT 78612 - search scope patch from Thomas Sibley
+0.15 21 Sept 2012
+ * RT 79776 - Net::LDAP >= 0.44 causes stop() to hang indefinitely. Added an alarm()
+ workaround to kill() the problem pid if waitpid() hangs.
+
View
27 lib/Net/LDAP/Server/Test.pm
@@ -7,7 +7,7 @@ use IO::Select;
use IO::Socket;
use Data::Dump ();
-our $VERSION = '0.14';
+our $VERSION = '0.15';
=head1 NAME
@@ -934,6 +934,9 @@ sub new {
}
else {
+ # this is the child
+ warn "child pid=$pid" if $ENV{LDAP_DEBUG};
+
return unless <$r_fh> =~ /Ready/; # newline varies
close($r_fh);
return bless( \$pid, $class );
@@ -950,12 +953,32 @@ servers in the same test. Otherwise, this method is typically not
needed and may even cause your tests to hang indefinitely if
they die prematurely. YMMV.
+To prevent waitpid() from blocking and hanging your test server,
+it is wrapped in an alarm() call, which will wait 2 seconds
+and then call kill() on the reluctant pid. You have been warned.
+
=cut
sub stop {
my $server = shift;
my $pid = $$server;
- return waitpid( $pid, 0 );
+ warn "\$pid = $pid" if $ENV{LDAP_DEBUG};
+ eval {
+ local $SIG{ALRM}
+ = sub { die "waitpid($pid, 0) took too long\n" }; # NB: \n required
+ alarm 2;
+ my $ret = waitpid( $pid, 0 );
+ warn "waitpid returned $ret" if $ENV{LDAP_DEBUG};
+ alarm 0;
+ };
+ if ($@) {
+ warn "$@";
+ kill( 1, $pid );
+ }
+ else {
+ warn "waitpid($pid, 0) worked" if $ENV{LDAP_DEBUG};
+ }
+ return $pid;
}
=head1 AUTHOR
View
2 t/01-ldap.t
@@ -1,3 +1,5 @@
+#!/usr/bin/env perl
+
use Test::More tests => 12;
use strict;

0 comments on commit 7830a11

Please sign in to comment.
Something went wrong with that request. Please try again.