From dd5a4f6497d4a5d94f61186a85516a56d7db8c29 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 8 Oct 2021 10:20:04 +0000 Subject: git: fatalize async callback errors by default This should help us catch BUG: errors (and then some) in -extindex and other read-write code paths. Only read-only daemons should warn on async callback failures, since those aren't capable of causing data loss. --- lib/PublicInbox/Git.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/Git.pm') diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index f15ace1a..7c08be47 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -26,6 +26,7 @@ our @EXPORT_OK = qw(git_unquote git_quote); our $PIPE_BUFSIZ = 65536; # Linux default our $in_cleanup; our $RDTIMEO = 60_000; # milliseconds +our $async_warn; # true in read-only daemons use constant MAX_INFLIGHT => (POSIX::PIPE_BUF * 3) / 65; # SHA-256 hex size + "\n" in preparation for git using non-SHA1 @@ -227,7 +228,7 @@ sub cat_async_step ($$) { } $self->{rbuf} = $rbuf if $$rbuf ne ''; eval { $cb->($bref, $oid, $type, $size, $arg) }; - warn "E: $oid: $@\n" if $@; + async_err($self, "E: cat $req ($oid) $@") if $@; } sub cat_async_wait ($) { @@ -273,7 +274,7 @@ sub check_async_step ($$) { } $self->{rbuf_c} = $rbuf if $$rbuf ne ''; eval { $cb->($hex, $type, $size, $arg, $self) }; - warn "E: check($req) $@\n" if $@; + async_err($self, "E: check $req ($hex) $@") if $@; } sub check_async_wait ($) { @@ -343,7 +344,7 @@ sub async_abort ($) { my ($req, $cb, $arg) = splice(@$q, 0, 3); $req =~ s/ .*//; # drop git_dir for Gcf2Client eval { $cb->(undef, $req, undef, undef, $arg) }; - warn "E: $req: $@ (in abort)\n" if $@; + warn "E: (in abort) $req: $@" if $@; } delete $self->{"inflight$c"}; delete $self->{"rbuf$c"}; @@ -358,6 +359,12 @@ sub fail { # may be augmented in subclasses croak(ref($self) . ' ' . ($self->{git_dir} // '') . ": $msg"); } +sub async_err ($$) { + my ($self, $msg) = @_; + return warn($msg) if $async_warn; + $self->fail($msg); +} + # $git->popen(qw(show f00)); # or # $git->popen(qw(show f00), { GIT_CONFIG => ... }, { 2 => ... }); sub popen { -- cgit v1.2.3-24-ge0c7