From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] lei: fix output race in client/daemon mode
Date: Sun, 3 Jan 2021 11:24:51 +0000 [thread overview]
Message-ID: <20210103112451.75313-3-e@80x24.org> (raw)
In-Reply-To: <20210103112451.75313-1-e@80x24.org>
The daemon needs to flush stdout before disconnecting or killing
clients, otherwise they may reread empty data on redirected
outputs. We also don't want to unbuffer stdout too early in
case we have lots of small chunks of data to output.
The received ($self->{2}) will always have autoflush, matching normal
STDERR behavior.
---
lib/PublicInbox/LEI.pm | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 3ad5e01a..6f21da35 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -236,6 +236,7 @@ my %CONFIG_KEYS = (
sub x_it ($$) { # pronounced "exit"
my ($self, $code) = @_;
+ $self->{1}->autoflush(1); # make sure client sees stdout before exit
if (my $sig = ($code & 127)) {
kill($sig, $self->{pid} // $$);
} else {
@@ -635,6 +636,7 @@ sub accept_dispatch { # Listener {post_accept} callback
say $sock "timed out waiting to recv FDs";
return;
}
+ $self->{2}->autoflush(1); # keep stdout buffered until x_it|DESTROY
# $ARGV_STR = join("]\0[", @ARGV);
# $ENV_STR = join('', map { "$_=$ENV{$_}\0" } keys %ENV);
# $line = "$$\0\0>$ARGV_STR\0\0>$ENV_STR\0\0";
@@ -773,4 +775,8 @@ sub oneshot {
}, __PACKAGE__), @ARGV);
}
+# ensures stdout hits the FS before sock disconnects so a client
+# can immediately reread it
+sub DESTROY { $_[0]->{1}->autoflush(1) }
+
1;
prev parent reply other threads:[~2021-01-03 11:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-03 9:48 [PATCH 0/3] lei-related test fixes Eric Wong
2021-01-03 9:48 ` [PATCH 1/3] t/lei: use $lei->() callback wrapper Eric Wong
2021-01-03 9:48 ` [PATCH 2/3] testcommon: prepare_redirects: fix error message Eric Wong
2021-01-03 9:48 ` [PATCH 3/3] spawn: support send_fd+recv_fd w/o IO::FDPass Eric Wong
2021-01-03 11:24 ` [PATCH 0/2] fix race from stdout buffering in FD pass exit Eric Wong
2021-01-03 11:24 ` [PATCH 1/2] send and receive all 3 FDs at once Eric Wong
2021-01-03 11:24 ` Eric Wong [this message]
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: http://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=20210103112451.75313-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).