From: Eric Wong Date: Sat, 25 Nov 2023 20:54:34 +0000 (+0000) Subject: select+poll: have caller retry on EINTR X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85f161be11a0c5561aa872fcadff3d08b8163ff6;p=thirdparty%2Fpublic-inbox.git select+poll: have caller retry on EINTR We can't assume signals are blocked when neither signalfd nor EVFILT_SIGNAL are in use. So just return an empty result so the caller can recalculate the timeout. I found this bug while making xt/httpd-async-stream.t use our event loop to reap processes but have abandoned that effort for now since it didn't save any code. --- diff --git a/lib/PublicInbox/DSPoll.pm b/lib/PublicInbox/DSPoll.pm index b947f7560..a7055ec9e 100644 --- a/lib/PublicInbox/DSPoll.pm +++ b/lib/PublicInbox/DSPoll.pm @@ -26,11 +26,9 @@ sub ep_wait { push(@pset, $fd, $pevents); } @$events = (); - do { - $n = IO::Poll::_poll($timeout_msec, @pset); - } while ($n < 0 && $! == Errno::EINTR); + $n = IO::Poll::_poll($timeout_msec, @pset) or return; # timeout expired + return if $n < 0 && $! == Errno::EINTR; # caller recalculates timeout die "poll: $!" if $n < 0; - return if $n == 0; while (defined($fd = shift @pset)) { $revents = shift @pset or next; # no event if ($revents & POLLNVAL) { diff --git a/lib/PublicInbox/Select.pm b/lib/PublicInbox/Select.pm index 5cb7aff3c..face8edc3 100644 --- a/lib/PublicInbox/Select.pm +++ b/lib/PublicInbox/Select.pm @@ -8,6 +8,7 @@ package PublicInbox::Select; use v5.12; use PublicInbox::Syscall qw(EPOLLONESHOT EPOLLIN EPOLLOUT); +use Errno; sub new { bless {}, __PACKAGE__ } # fd => events @@ -19,8 +20,9 @@ sub ep_wait { vec($wvec, $fd, 1) = 1 if $ev & EPOLLOUT; } @$events = (); - my $n = select($rvec, $wvec, undef, $msec < 0 ? undef : ($msec/1000)); - return if $n == 0; + my $to = $msec < 0 ? undef : ($msec/1000); + my $n = select $rvec, $wvec, undef, $to or return; # timeout expired + return if $n < 0 && $! == Errno::EINTR; # caller recalculates timeout die "select: $!" if $n < 0; while (my ($fd, $ev) = each %$self) { if (vec($rvec, $fd, 1) || vec($wvec, $fd, 1)) {