From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/3] script/lei: handle SIGTSTP and SIGCONT
Date: Tue, 21 Sep 2021 09:29:44 +0000 [thread overview]
Message-ID: <20210921092945.23916-3-e@80x24.org> (raw)
In-Reply-To: <20210921092945.23916-1-e@80x24.org>
Sometimes it's useful to pause an expensive query or
refresh-mail-sync to do something else. While lei-daemon and
lei/store can't be paused since they're shared across clients,
per-invocation WQ workers can be paused safely using the
unblockable SIGSTOP.
While we're at it, drop the ETOOMANYREFS hint since it
hasn't been a problem since we drastically reduced FD passing
early in development.
---
lib/PublicInbox/LEI.pm | 18 ++++++++++++------
script/lei | 9 ++++-----
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index f94bfa45..2df1f326 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -1118,23 +1118,28 @@ sub dclose {
sub event_step {
my ($self) = @_;
local %ENV = %{$self->{env}};
- my $sock = $self->{sock};
local $current_lei = $self;
eval {
- while (my @fds = $recv_cmd->($sock, my $buf, 4096)) {
+ my $buf;
+ while (my @fds = $recv_cmd->($self->{sock}, $buf, 4096)) {
if (scalar(@fds) == 1 && !defined($fds[0])) {
return if $! == EAGAIN;
next if $! == EINTR;
last if $! == ECONNRESET;
die "recvmsg: $!";
}
- for my $fd (@fds) {
- open my $rfh, '+<&=', $fd;
+ for (@fds) { open my $rfh, '+<&=', $_ }
+ }
+ if ($buf eq '') {
+ _drop_wq($self); # EOF, client disconnected
+ dclose($self);
+ } elsif ($buf =~ /\A(STOP|CONT)\z/) {
+ for my $wq (grep(defined, @$self{@WQ_KEYS})) {
+ $wq->wq_kill($buf) or $wq->wq_kill_old($buf);
}
+ } else {
die "unrecognized client signal: $buf";
}
- _drop_wq($self); # EOF, client disconnected
- dclose($self);
};
if (my $err = $@) {
eval { $self->fail($err) };
@@ -1146,6 +1151,7 @@ sub event_step_init {
my ($self) = @_;
my $sock = $self->{sock} or return;
$self->{-event_init_done} //= do { # persist til $ops done
+ $sock->blocking(0);
$self->SUPER::new($sock, EPOLLIN|EPOLLET);
$sock;
};
diff --git a/script/lei b/script/lei
index 591013e3..399296ba 100755
--- a/script/lei
+++ b/script/lei
@@ -106,11 +106,10 @@ open my $dh, '<', '.' or die "open(.) $!";
my $buf = join("\0", scalar(@ARGV), @ARGV);
while (my ($k, $v) = each %ENV) { $buf .= "\0$k=$v" }
$buf .= "\0\0";
-my $n = $send_cmd->($sock, [0, 1, 2, fileno($dh)], $buf, MSG_EOR);
-if (!$n) {
- die "sendmsg: $! (check RLIMIT_NOFILE)\n" if $!{ETOOMANYREFS};
- die "sendmsg: $!\n";
-}
+$send_cmd->($sock, [0, 1, 2, fileno($dh)], $buf, MSG_EOR) or die "sendmsg: $!";
+$SIG{TSTP} = sub { $send_cmd->($sock, [], 'STOP', MSG_EOR); kill 'STOP', $$ };
+$SIG{CONT} = sub { $send_cmd->($sock, [], 'CONT', MSG_EOR) };
+
my $x_it_code = 0;
while (1) {
my (@fds) = $recv_cmd->($sock, my $buf, 4096 * 33);
next prev parent reply other threads:[~2021-09-21 9:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-21 7:41 [PATCH 00/12] lei: fix various annoyances Eric Wong
2021-09-21 7:41 ` [PATCH 01/12] lei inspect: convert to WQ worker Eric Wong
2021-09-21 7:41 ` [PATCH 02/12] lei inspect: support NNTP URLs Eric Wong
2021-09-21 7:41 ` [PATCH 03/12] lei_mail_sync: account for non-unique cases Eric Wong
2021-09-21 7:41 ` [PATCH 04/12] lei: simplify internal arg2folder usage Eric Wong
2021-09-21 7:41 ` [PATCH 05/12] lei lcat: use single queue for ordering Eric Wong
2021-09-21 7:41 ` [PATCH 06/12] doc: lei-security: section for WIP auth methods Eric Wong
2021-09-21 7:41 ` [PATCH 07/12] lei lcat: support NNTP URLs Eric Wong
2021-09-21 7:41 ` [PATCH 08/12] lei: various completion improvements Eric Wong
2021-09-21 7:41 ` [PATCH 09/12] lei q: show progress on >1s preparation phase Eric Wong
2021-09-21 7:41 ` [PATCH 10/12] search: drop reopen retry message Eric Wong
2021-09-21 7:41 ` [PATCH 11/12] lei q: update messages to reflect --save default Eric Wong
2021-09-21 7:41 ` [PATCH 12/12] lei q: improve --limit behavior and progress Eric Wong
2021-09-21 9:29 ` [PATCH 0/3] lei: a few more annoyances fixed Eric Wong
2021-09-21 9:29 ` [PATCH 1/3] t/lei-up: use '-q' to silence non-redirected test Eric Wong
2021-09-21 9:29 ` Eric Wong [this message]
2021-09-21 9:29 ` [PATCH 3/3] lei: umask(077) before opening errors.log 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=20210921092945.23916-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).