user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 1/4] testcommon: DESTROY: wait for killed daemon
Date: Sat, 11 Apr 2020 10:53:27 +0000	[thread overview]
Message-ID: <20200411105330.19544-2-e@yhbt.net> (raw)
In-Reply-To: <20200411105330.19544-1-e@yhbt.net>

Otherwise, the waitpid(-1, 0) call in Xapcmd::process_queue()
may reap it in a subsequent test when using t/run.perl to reuse
processes for testing.

While we're at it, make Xapcmd::process_queue warn about unknown
PIDs in case other PIDs leak through to us in the future.
---
 lib/PublicInbox/TestCommon.pm | 6 +++---
 lib/PublicInbox/Xapcmd.pm     | 6 +++++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 6e3e9d8c..e9efbac7 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -319,8 +319,9 @@ sub kill {
 }
 
 sub join {
-	my ($self) = @_;
+	my ($self, $sig) = @_;
 	my $pid = delete $self->{pid} or return;
+	CORE::kill($sig, $pid) if defined $sig;
 	my $ret = waitpid($pid, 0);
 	defined($ret) or die "waitpid($pid): $!";
 	$ret == $pid or die "waitpid($pid) != $ret";
@@ -333,8 +334,7 @@ sub DESTROY {
 		PublicInbox::TestCommon::wait_for_tail();
 		CORE::kill('TERM', $tail);
 	}
-	my $pid = delete $self->{pid} or return;
-	CORE::kill('TERM', $pid);
+	$self->join('TERM');
 }
 
 1;
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 8e2b9063..337978bd 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -142,7 +142,11 @@ sub process_queue {
 		while (scalar keys %pids) {
 			my $pid = waitpid(-1, 0);
 			my $args = delete $pids{$pid};
-			die join(' ', @$args)." failed: $?\n" if $?;
+			if ($args) {
+				die join(' ', @$args)." failed: $?\n" if $?;
+			} else {
+				warn "unknown PID($pid) reaped: $?\n";
+			}
 		}
 	}
 }

  reply	other threads:[~2020-04-11 10:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11 10:53 [PATCH 0/4] FreeBSD and test fixes Eric Wong
2020-04-11 10:53 ` Eric Wong [this message]
2020-04-11 10:53 ` [PATCH 2/4] dskqxs: ignore EV_SET errors on EVFILT_WRITE Eric Wong
2020-04-11 10:53 ` [PATCH 3/4] t/*.t: localize $SIG{__WARN__} changes Eric Wong
2020-04-11 10:53 ` [PATCH 4/4] t/httpd-corner.t: relax read-after-failed-write handling Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200411105330.19544-2-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).