user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/3] select+poll: have caller retry on EINTR
Date: Sat, 25 Nov 2023 20:54:34 +0000	[thread overview]
Message-ID: <20231125205435.4187895-3-e@80x24.org> (raw)
In-Reply-To: <20231125205435.4187895-1-e@80x24.org>

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.
---
 lib/PublicInbox/DSPoll.pm | 6 ++----
 lib/PublicInbox/Select.pm | 6 ++++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/DSPoll.pm b/lib/PublicInbox/DSPoll.pm
index b947f756..a7055ec9 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 5cb7aff3..face8edc 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)) {

  parent reply	other threads:[~2023-11-25 20:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-25 20:54 [PATCH 0/3] ds: event loop-related fixes Eric Wong
2023-11-25 20:54 ` [PATCH 1/3] http: fix pipelining during long async requests Eric Wong
2023-11-25 20:54 ` Eric Wong [this message]
2023-11-25 20:54 ` [PATCH 3/3] ds: long_step: eliminate redundant fileno call Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231125205435.4187895-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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