From fd261b9e6567450573531fadec741ec887d9d6b3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 15 Aug 2022 19:28:33 +0000 Subject: lei_store_err: use level-trigger for error pipe This fixes deadlocks from errors inside lei/store when multiple errors are spewed. --- lib/PublicInbox/LeiStoreErr.pm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lib/PublicInbox/LeiStoreErr.pm') diff --git a/lib/PublicInbox/LeiStoreErr.pm b/lib/PublicInbox/LeiStoreErr.pm index cc085fdc..47fa2277 100644 --- a/lib/PublicInbox/LeiStoreErr.pm +++ b/lib/PublicInbox/LeiStoreErr.pm @@ -1,13 +1,12 @@ -# Copyright (C) 2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # forwards stderr from lei/store process to any lei clients using # the same store, falls back to syslog if no matching clients exist. package PublicInbox::LeiStoreErr; -use strict; -use v5.10.1; +use v5.12; use parent qw(PublicInbox::DS); -use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT); +use PublicInbox::Syscall qw(EPOLLIN); use Sys::Syslog qw(openlog syslog closelog); use IO::Handle (); # ->blocking @@ -15,24 +14,24 @@ sub new { my ($cls, $rd, $lei) = @_; my $self = bless { sock => $rd, store_path => $lei->store_path }, $cls; $rd->blocking(0); - $self->SUPER::new($rd, EPOLLIN | EPOLLONESHOT); + $self->SUPER::new($rd, EPOLLIN); # level-trigger } sub event_step { my ($self) = @_; - my $rbuf = $self->{rbuf} // \(my $x = ''); - $self->do_read($rbuf, 8192, length($$rbuf)) or return; - my $cb; + my $n = sysread($self->{sock}, my $buf, 8192); + return ($!{EAGAIN} ? 0 : $self->close) if !defined($n); + return $self->close if !$n; my $printed; for my $lei (values %PublicInbox::DS::DescriptorMap) { - $cb = $lei->can('store_path') // next; + my $cb = $lei->can('store_path') // next; next if $cb->($lei) ne $self->{store_path}; my $err = $lei->{2} // next; - print $err $$rbuf and $printed = 1; + print $err $buf and $printed = 1; } if (!$printed) { openlog('lei/store', 'pid,nowait,nofatal,ndelay', 'user'); - for my $l (split(/\n/, $$rbuf)) { syslog('warning', '%s', $l) } + for my $l (split(/\n/, $buf)) { syslog('warning', '%s', $l) } closelog(); # don't share across fork } } -- cgit v1.2.3-24-ge0c7