From 21ce1a28915374297829bd05feda0cea52adb324 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 31 Jan 2021 22:28:16 -1000 Subject: lei: remove SIGPIPE handler It doesn't save us any code, and the action-at-a-distance element was making it confusing to track down actual problems. Another potential problem was keeping references alive too long. So do like we would a C100K server and check every write while still ensuring lei(1) exit with a proper SIGPIPE iff needed. --- lib/PublicInbox/LeiOverview.pm | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'lib/PublicInbox/LeiOverview.pm') diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm index fa041457..1d62ffe2 100644 --- a/lib/PublicInbox/LeiOverview.pm +++ b/lib/PublicInbox/LeiOverview.pm @@ -107,28 +107,22 @@ sub new { sub ovv_begin { my ($self, $lei) = @_; if ($self->{fmt} eq 'json') { - print { $lei->{1} } '['; + $lei->out('['); } # TODO HTML/Atom/... } # called once by parent (via PublicInbox::EOFpipe) sub ovv_end { my ($self, $lei) = @_; - my $out = $lei->{1} or return; if ($self->{fmt} eq 'json') { # JSON doesn't allow trailing commas, and preventing # trailing commas is a PITA when parallelizing outputs - print $out "null]\n"; + $lei->out("null]\n"); } elsif ($self->{fmt} eq 'concatjson') { - print $out "\n"; + $lei->out("\n"); } } -sub ovv_atfork_child { - my ($self) = @_; - # reopen dedupe here -} - # prepares an smsg for JSON sub _unbless_smsg { my ($smsg, $mitem) = @_; @@ -168,9 +162,8 @@ sub ovv_atexit_child { $git->async_wait_all; } if (my $bref = delete $lei->{ovv_buf}) { - my $out = $lei->{1} or return; my $lk = $self->lock_for_scope; - print $out $$bref; + $lei->out($$bref); } } @@ -268,11 +261,10 @@ sub ovv_each_smsg_cb { # runs in wq worker usually } } sort keys %$smsg); $buf .= $EOR; - if (length($buf) > 65536) { - my $lk = $self->lock_for_scope; - print { $lei->{1} } $buf; - $buf = ''; - } + return if length($buf) < 65536; + my $lk = $self->lock_for_scope; + $lei->out($buf); + $buf = ''; } } elsif ($json) { my $ORS = $self->{fmt} eq 'json' ? ",\n" : "\n"; # JSONL @@ -280,11 +272,10 @@ sub ovv_each_smsg_cb { # runs in wq worker usually my ($smsg, $mitem) = @_; return if $dedupe->is_smsg_dup($smsg); $buf .= $json->encode(_unbless_smsg(@_)) . $ORS; - if (length($buf) > 65536) { - my $lk = $self->lock_for_scope; - print { $lei->{1} } $buf; - $buf = ''; - } + return if length($buf) < 65536; + my $lk = $self->lock_for_scope; + $lei->out($buf); + $buf = ''; } } # else { ... } -- cgit v1.2.3-24-ge0c7