From 364d2e95439b00a211d007d93c5ba263b56c1ddf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 8 Jul 2019 07:01:59 +0000 Subject: ds: use WNOHANG with waitpid if inside event loop While we're usually not stuck waiting on waitpid after seeing a pipe EOF or even triggering SIGPIPE in the process (e.g. git-http-backend) we're reading from, it MAY happen and we should be careful to never hang the daemon process on waitpid calls. v2: use "eq" for string comparison against 'DEFAULT' --- lib/PublicInbox/ProcessPipe.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/ProcessPipe.pm') diff --git a/lib/PublicInbox/ProcessPipe.pm b/lib/PublicInbox/ProcessPipe.pm index 2769e064..4f5fc751 100644 --- a/lib/PublicInbox/ProcessPipe.pm +++ b/lib/PublicInbox/ProcessPipe.pm @@ -20,8 +20,13 @@ sub CLOSE { my $ret = defined $fh ? close($fh) : ''; my $pid = delete $_[0]->{pid}; if (defined $pid) { - waitpid($pid, 0); - $ret = '' if $?; + # PublicInbox::DS may not be loaded + eval { PublicInbox::DS::dwaitpid($pid, undef, undef) }; + + if ($@) { # ok, not in the event loop, work synchronously + waitpid($pid, 0); + $ret = '' if $?; + } } $ret; } -- cgit v1.2.3-24-ge0c7