From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4408C1F5A4 for ; Thu, 19 Jan 2023 20:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1674160358; bh=Fxg9K8TLLTuuRVL9iUBcWKOp842QvPWNl8ZRi66fa/w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=12kmgQXcP4HpI1NF4LHzi9bxufPd9hQ+sVJHrueDUlK/A/+ZVV/l7G7a0vxZhjnDw X2VSY30Shrx1LnvkAsfKg21yIjFchropzLPYzDdtYkL7l2h6iT4nq6gyNTR9ExDlZ+ DeRClwEOEH21TyLR78pEPZJOn/4BxL04+9GIwWog= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/4] ds: improve error handling of synchronous awaitpid Date: Thu, 19 Jan 2023 20:32:36 +0000 Message-Id: <20230119203237.2277543-4-e@80x24.org> In-Reply-To: <20230119203237.2277543-1-e@80x24.org> References: <20230119203237.2277543-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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;