unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/2] "make check-run" fixed
@ 2021-04-28 19:37 Eric Wong
  2021-04-28 19:37 ` [PATCH 1/2] t/run: support TEST_RUN_LOG to diagnose process death Eric Wong
  2021-04-28 19:37 ` [PATCH 2/2] lei: avoid close(STD{IN,OUT,ERR}) in oneshot mode Eric Wong
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2021-04-28 19:37 UTC (permalink / raw)
  To: meta

It turns out the oneshot mode of lei was causing problems and
propagating them to other tests.  1/2 helped me finally get to
the bottom of it and fix it in 2/2.

Eric Wong (2):
  t/run: support TEST_RUN_LOG to diagnose process death
  lei: avoid close(STD{IN,OUT,ERR}) in oneshot mode

 lib/PublicInbox/LEI.pm | 18 ++++--------------
 t/lei.t                |  1 +
 t/run.perl             | 18 +++++++++++++++++-
 3 files changed, 22 insertions(+), 15 deletions(-)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] t/run: support TEST_RUN_LOG to diagnose process death
  2021-04-28 19:37 [PATCH 0/2] "make check-run" fixed Eric Wong
@ 2021-04-28 19:37 ` Eric Wong
  2021-04-28 19:37 ` [PATCH 2/2] lei: avoid close(STD{IN,OUT,ERR}) in oneshot mode Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-04-28 19:37 UTC (permalink / raw)
  To: meta

Knowing which process ran what before dying unexpectedly
helps with debugging.
---
 t/run.perl | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/t/run.perl b/t/run.perl
index 2fbe4033..acd60ff5 100755
--- a/t/run.perl
+++ b/t/run.perl
@@ -19,6 +19,7 @@ use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use Errno qw(EINTR);
 use Fcntl qw(:seek);
 use POSIX qw(_POSIX_PIPE_BUF WNOHANG);
+use File::Temp ();
 my $jobs = 1;
 my $repeat = 1;
 $| = 1;
@@ -39,6 +40,15 @@ open my $OLDERR, '>&STDERR' or die "dup STDERR: $!";
 $OLDOUT->autoflush(1);
 $OLDERR->autoflush(1);
 
+my ($run_log, $tmp_rl);
+my $rl = $ENV{TEST_RUN_LOG};
+unless ($rl) {
+	$tmp_rl = File::Temp->new(CLEANUP => 1);
+	$rl = $tmp_rl->filename;
+}
+open $run_log, '+>>', $rl or die "open $rl: $!";
+$run_log->autoflush(1); # one reader, many writers
+
 key2sub($_) for @tests; # precache
 
 my ($for_destroy, $lei_env, $lei_daemon_pid, $owner_pid);
@@ -120,6 +130,7 @@ END { test_status() if (defined($worker_test) && $worker == $$) }
 
 sub run_test ($) {
 	my ($test) = @_;
+	syswrite($run_log, "$$ $test\n");
 	my $log_fh;
 	if ($log_suffix ne '') {
 		my $log = $test;
@@ -205,7 +216,12 @@ for (my $i = $repeat; $i != 0; $i--) {
 				push @err, "reaped unknown $pid ($?)";
 				next;
 			}
-			push @err, "job[$j] ($?)" if $?;
+			if ($?) {
+				seek($run_log, 0, SEEK_SET);
+				chomp(my @t = grep(/^$pid /, <$run_log>));
+				$t[0] //= "$pid unknown";
+				push @err, "job[$j] ($?) PID=$t[-1]";
+			}
 			# skip_all can exit(0), respawn if needed:
 			if (!$eof) {
 				print $OLDERR "# respawning job[$j]\n";

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] lei: avoid close(STD{IN,OUT,ERR}) in oneshot mode
  2021-04-28 19:37 [PATCH 0/2] "make check-run" fixed Eric Wong
  2021-04-28 19:37 ` [PATCH 1/2] t/run: support TEST_RUN_LOG to diagnose process death Eric Wong
@ 2021-04-28 19:37 ` Eric Wong
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2021-04-28 19:37 UTC (permalink / raw)
  To: meta

This seems to fix the occasional "make check-run" failures I've
been chasing.

Some parts of our code assumes we can close($lei->{1})
and similar, which causes IO::Handle::autoflush to behave
badly when STDOUT is the "select"-ed FH of the Perl process.
Since oneshot mode is (hopefully) the uncommon case, we'll
just accept the cost of extra FDs and minimize differences
between lei in oneshot vs daemon mode.
---
 lib/PublicInbox/LEI.pm | 18 ++++--------------
 t/lei.t                |  1 +
 2 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 7ffcf163..1ea7c9ca 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -487,19 +487,14 @@ sub _lei_atfork_child {
 	# we need to explicitly close things which are on stack
 	if ($persist) {
 		chdir '/' or die "chdir(/): $!";
-		my @io = delete @$self{qw(0 1 2 sock)};
-		unless ($self->{oneshot}) {
-			close($_) for @io;
-		}
+		close($_) for (grep(defined, delete @$self{qw(0 1 2 sock)}));
 		if (my $cfg = $self->{cfg}) {
 			delete $cfg->{-lei_store};
 		}
 	} else { # worker, Net::NNTP (Net::Cmd) uses STDERR directly
 		open STDERR, '+>&='.fileno($self->{2}) or warn "open $!";
 	}
-	for (delete @$self{qw(3 old_1 au_done)}) {
-		close($_) if defined($_);
-	}
+	close($_) for (grep(defined, delete @$self{qw(3 old_1 au_done)}));
 	if (my $op_c = delete $self->{pkt_op_c}) {
 		close(delete $op_c->{sock});
 	}
@@ -1213,13 +1208,8 @@ sub oneshot {
 	local $quit = $exit if $exit;
 	local %PATH2CFG;
 	umask(077) // die("umask(077): $!");
-	my $self = bless {
-		oneshot => 1,
-		0 => *STDIN{GLOB},
-		1 => *STDOUT{GLOB},
-		2 => *STDERR{GLOB},
-		env => \%ENV
-	}, __PACKAGE__;
+	my $self = bless { oneshot => 1, env => \%ENV }, __PACKAGE__;
+	for (0..2) { open($self->{$_}, '+<&=', $_) or die "open fd=$_: $!" }
 	dispatch($self, @ARGV);
 	x_it($self, $self->{child_error}) if $self->{child_error};
 }
diff --git a/t/lei.t b/t/lei.t
index 6d276050..8211c01d 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -154,6 +154,7 @@ my $test_fail = sub {
 		}
 	}
 	lei_ok('sucks', \'yes, but hopefully less every day');
+	like($lei_out, qr/loaded features/, 'loaded features shown');
 SKIP: {
 	skip 'no curl', 3 unless which('curl');
 	lei(qw(q --only http://127.0.0.1:99999/bogus/ t:m));

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-28 19:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 19:37 [PATCH 0/2] "make check-run" fixed Eric Wong
2021-04-28 19:37 ` [PATCH 1/2] t/run: support TEST_RUN_LOG to diagnose process death Eric Wong
2021-04-28 19:37 ` [PATCH 2/2] lei: avoid close(STD{IN,OUT,ERR}) in oneshot mode Eric Wong

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).