From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 2/2] t/httpd-unix: reliability for non-signalfd/EVFILT_SIGNAL
Date: Thu, 16 Apr 2020 01:48:38 +0000 [thread overview]
Message-ID: <20200416014838.5939-3-e@yhbt.net> (raw)
In-Reply-To: <20200416014838.5939-1-e@yhbt.net>
Perl seems unable to detect a pending signal (`PL_sig_pending' flag)
even in a sleep(1) loop which wakes up every second.
The (SIGTTOU|SIGUSR2|SIGQUIT) signal itself in the
`PL_psig_pend[sig]' array is not lost, so we can send SIGCHLD
to the process to force the `PL_sig_pending' into being set,
again.
I tested this commit in a loop with the following patch on a
Debian GNU/Linux system to disable signalfd use:
diff --git a/lib/PublicInbox/Sigfd.pm b/lib/PublicInbox/Sigfd.pm
index f500902e..597b40d1 100644
--- a/lib/PublicInbox/Sigfd.pm
+++ b/lib/PublicInbox/Sigfd.pm
@@ -12,6 +12,7 @@ use IO::Handle ();
# are available.
sub new {
my ($class, $sig, $flags) = @_;
+ return;
my $self = fields::new($class);
my %signo = map {;
my $cb = $sig->{$_};
---
t/httpd-unix.t | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/t/httpd-unix.t b/t/httpd-unix.t
index 7ebc3464..3bfded0c 100644
--- a/t/httpd-unix.t
+++ b/t/httpd-unix.t
@@ -81,13 +81,27 @@ check_sock($unix);
ok(-S $unix, 'unix socket still exists');
}
+# Perl can delay signal dispatches due to races, so we repeatedly
+# poke a process with an innocuous signal (SIGCHLD) when signalfd(2)
+# (or EVFILT_SIGNAL) is missing
+my $sig_poke;
+if (my $sigfd = PublicInbox::Sigfd->new({}, 0)) {
+ $sig_poke = sub {}; # noop, we've got signalfd or EVFILT_SIGNAL
+} else {
+ $sig_poke = sub {
+ my $pid = shift;
+ kill('CHLD', $pid);
+ };
+}
+
sub delay_until {
my $cond = shift;
- for (1..1000) {
+ my $end = time + 30;
+ do {
return if $cond->();
select undef, undef, undef, 0.012;
- }
- Carp::croak('condition failed');
+ } until (time > $end);
+ Carp::confess('condition failed');
}
SKIP: {
@@ -133,19 +147,23 @@ SKIP: {
kill('USR2', $pid) or die "USR2 failed: $!";
delay_until(sub {
+ $sig_poke->($pid);
$pid != (eval { $read_pid->($pid_file) } // $pid)
});
my $new_pid = $read_pid->($pid_file);
isnt($new_pid, $pid, 'new child started');
+ ok($new_pid > 0, '$new_pid valid');
delay_until(sub { -s "$pid_file.oldbin" });
my $old_pid = $read_pid->("$pid_file.oldbin");
is($old_pid, $pid, '.oldbin pid file written');
+ ok($old_pid > 0, '$old_pid valid');
check_sock($unix); # ensures $new_pid is ready to receive signals
# first, back out of the upgrade
kill('QUIT', $new_pid) or die "kill new PID failed: $!";
delay_until(sub {
+ $sig_poke->($new_pid);
$pid == (eval { $read_pid->($pid_file) } // 0)
});
is($read_pid->($pid_file), $pid, 'old PID file restored');
next prev parent reply other threads:[~2020-04-16 1:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-16 1:48 [PATCH 0/2] more test fixes Eric Wong
2020-04-16 1:48 ` [PATCH 1/2] t/httpd-corner: improve reliability and diagnostics Eric Wong
2020-04-16 1:48 ` Eric Wong [this message]
2020-04-17 5:22 ` [PATCHv2 2/2] t/httpd-unix: skip some tests w/o signalfd|EVFILT_SIGNAL 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=20200416014838.5939-3-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).