* [PATCH 1/4] qspawn: {quiet} only affects normal command exit
2023-01-19 20:32 [PATCH 0/4] qspawn|awaitpid error handling improvements Eric Wong
@ 2023-01-19 20:32 ` Eric Wong
2023-01-19 20:32 ` [PATCH 2/4] qspawn: psgi_qx: do not call async_pass on errors Eric Wong
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-19 20:32 UTC (permalink / raw)
To: meta
{quiet} is nice for quieting normal/expected errors (e.g `git diff'),
but we still want to show the command in case there's errors in
our own code.
---
lib/PublicInbox/Qspawn.pm | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index 78afe718..c4708c0f 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -57,7 +57,8 @@ sub _do_spawn {
$o{$k} = $rlimit;
}
}
- $self->{cmd} = $o{quiet} ? undef : $cmd;
+ $self->{cmd} = $cmd;
+ $self->{-quiet} = 1 if $o{quiet};
$o{cb_arg} = [ \&waitpid_err, $self ];
eval {
# popen_rd may die on EMFILE, ENFILE
@@ -85,7 +86,7 @@ sub finalize ($) {
if (my $dst = $self->{qsp_err}) {
$$dst .= $$dst ? " $err" : "; $err";
}
- warn "@{$self->{cmd}}: $err" if $self->{cmd};
+ warn "@{$self->{cmd}}: $err" if !$self->{-quiet};
}
my ($env, $qx_cb, $qx_arg, $qx_buf) =
@@ -216,9 +217,8 @@ sub rd_hdr ($) {
warn "parse_hdr: $@";
$ret = [ 500, [], [ "Internal error\n" ] ];
} elsif (!defined($ret) && !$r) {
- my $cmd = $self->{cmd} // [ '(?)' ];
warn <<EOM;
-EOF parsing headers from @$cmd ($self->{psgi_env}->{REQUEST_URI})
+EOF parsing headers from @{$self->{cmd}} ($self->{psgi_env}->{REQUEST_URI})
EOM
$ret = [ 500, [], [ "Internal error\n" ] ];
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] qspawn: psgi_qx: do not call async_pass on errors
2023-01-19 20:32 [PATCH 0/4] qspawn|awaitpid error handling improvements Eric Wong
2023-01-19 20:32 ` [PATCH 1/4] qspawn: {quiet} only affects normal command exit Eric Wong
@ 2023-01-19 20:32 ` Eric Wong
2023-01-19 20:32 ` [PATCH 3/4] ds: improve error handling of synchronous awaitpid Eric Wong
2023-01-19 20:32 ` [PATCH 4/4] qspawn: drop unnecessary awaitpid import Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-19 20:32 UTC (permalink / raw)
To: meta
This makes control flow slightly less confusing.
---
lib/PublicInbox/Qspawn.pm | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index c4708c0f..de74b174 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -142,20 +142,20 @@ sub start ($$$) {
sub psgi_qx_init_cb { # this may be PublicInbox::HTTPD::Async {cb}
my ($self) = @_;
- my $async = delete $self->{async}; # PublicInbox::HTTPD::Async
my ($r, $buf);
- my $qx_fh = $self->{qx_fh};
reread:
$r = sysread($self->{rpipe}, $buf, 65536);
- if ($async) {
- $async->async_pass($self->{psgi_env}->{'psgix.io'},
- $qx_fh, \$buf);
- } elsif (defined $r) {
- $r ? (print $qx_fh $buf) : event_step($self, undef);
- } else {
+ if (!defined($r)) {
return if $! == EAGAIN; # try again when notified
goto reread if $! == EINTR;
event_step($self, $!);
+ } elsif (my $as = delete $self->{async}) { # PublicInbox::HTTPD::Async
+ $as->async_pass($self->{psgi_env}->{'psgix.io'},
+ $self->{qx_fh}, \$buf);
+ } elsif ($r) { # generic PSGI:
+ print { $self->{qx_fh} } $buf;
+ } else { # EOF
+ event_step($self, undef);
}
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] ds: improve error handling of synchronous awaitpid
2023-01-19 20:32 [PATCH 0/4] qspawn|awaitpid error handling improvements Eric Wong
2023-01-19 20:32 ` [PATCH 1/4] qspawn: {quiet} only affects normal command exit Eric Wong
2023-01-19 20:32 ` [PATCH 2/4] qspawn: psgi_qx: do not call async_pass on errors Eric Wong
@ 2023-01-19 20:32 ` Eric Wong
2023-01-19 20:32 ` [PATCH 4/4] qspawn: drop unnecessary awaitpid import Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-19 20:32 UTC (permalink / raw)
To: meta
EINTR needs to be retried for non-kqueue|signalfd users,
and ECHILD indicates a bug in our code.
---
lib/PublicInbox/DS.pm | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index c849f515..523d47e4 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -30,7 +30,7 @@ use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
use Scalar::Util qw(blessed);
use PublicInbox::Syscall qw(:epoll);
use PublicInbox::Tmpfile;
-use Errno qw(EAGAIN EINVAL);
+use Errno qw(EAGAIN EINVAL ECHILD EINTR);
use Carp qw(carp croak);
our @EXPORT_OK = qw(now msg_more awaitpid add_timer add_uniq_timer);
@@ -703,13 +703,19 @@ sub awaitpid {
$AWAIT_PIDS->{$pid} //= @cb_args ? \@cb_args : 0;
# provide synchronous API
if (defined(wantarray) || (!$in_loop && !@cb_args)) {
- my $ret = waitpid($pid, 0) // -2;
+ my $ret;
+again:
+ $ret = waitpid($pid, 0) // -2;
if ($ret == $pid) {
my $cb_args = delete $AWAIT_PIDS->{$pid};
@cb_args = @$cb_args if !@cb_args && $cb_args;
await_cb($pid, @cb_args);
- return $ret;
+ } else {
+ goto again if $! == EINTR;
+ carp "waitpid($pid): $!";
+ delete $AWAIT_PIDS->{$pid};
}
+ return $ret;
}
# We could've just missed our SIGCHLD, cover it, here:
enqueue_reap() if $in_loop;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] qspawn: drop unnecessary awaitpid import
2023-01-19 20:32 [PATCH 0/4] qspawn|awaitpid error handling improvements Eric Wong
` (2 preceding siblings ...)
2023-01-19 20:32 ` [PATCH 3/4] ds: improve error handling of synchronous awaitpid Eric Wong
@ 2023-01-19 20:32 ` Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2023-01-19 20:32 UTC (permalink / raw)
To: meta
We don't actually need to call awaitpid here, ProcessPipe
will take care of that.
---
lib/PublicInbox/Qspawn.pm | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index de74b174..cc81a4cd 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -28,7 +28,6 @@ package PublicInbox::Qspawn;
use v5.12;
use PublicInbox::Spawn qw(popen_rd);
use PublicInbox::GzipFilter;
-use PublicInbox::DS qw(awaitpid);
use Scalar::Util qw(blessed);
# n.b.: we get EAGAIN with public-inbox-httpd, and EINTR on other PSGI servers
^ permalink raw reply related [flat|nested] 5+ messages in thread