* [PATCH 3/3] git: fatalize async callback errors by default
2021-10-08 10:20 6% [PATCH 0/3] git: propagate die from async callbacks Eric Wong
@ 2021-10-08 10:20 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-10-08 10:20 UTC (permalink / raw)
To: meta
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/Daemon.pm | 2 ++
lib/PublicInbox/Git.pm | 13 ++++++++++---
t/git.t | 24 ++++++++++++++++++++++++
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 5be474fa8754..0acd4ee9946c 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -18,6 +18,7 @@ use PublicInbox::DS qw(now);
require PublicInbox::Listener;
use PublicInbox::EOFpipe;
use PublicInbox::Sigfd;
+use PublicInbox::Git;
use PublicInbox::GitAsyncCat;
our $SO_ACCEPTFILTER = 0x1000;
my @CMD;
@@ -640,6 +641,7 @@ sub run ($$$;$) {
# localize GCF2C for tests:
local $PublicInbox::GitAsyncCat::GCF2C;
+ local $PublicInbox::Git::async_warn = 1;
daemon_loop($refresh, $post_accept, $tlsd, $af_default);
PublicInbox::DS->Reset;
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index f15ace1a3d62..7c08be47bbe4 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 {
diff --git a/t/git.t b/t/git.t
index 2a189eac6c40..8a02021103ff 100644
--- a/t/git.t
+++ b/t/git.t
@@ -68,6 +68,30 @@ use_ok 'PublicInbox::Git';
is_deeply($raw, $bref, 'blob result matches');
is_deeply($missing, [ undef, 'non-existent', 'missing', undef, $arg],
'non-existent blob gives expected result');
+
+ $res = [];
+ $gcf->cat_async($oid, sub { push @$res, \@_ });
+ $gcf->cat_async($oid, sub { die 'HI' });
+ $gcf->cat_async($oid, sub { push @$res, \@_ });
+ eval { $gcf->async_wait_all };
+ like($@, qr/\bHI\b/, 'die in callback propagates');
+ is(scalar(@$res), 2, 'two results');
+ is_deeply($res->[0], [ $raw, @x, undef ], '1st cb result');
+ is_deeply($res->[1], [ undef, $oid, undef, undef, undef ],
+ '2nd cb aborted ');
+
+ my @w;
+ local $PublicInbox::Git::async_warn = 1;
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ $res = [];
+ $gcf->cat_async($oid, sub { push @$res, \@_ });
+ $gcf->cat_async($oid, sub { die 'HI' });
+ $gcf->cat_async($oid, sub { push @$res, \@_ });
+ eval { $gcf->async_wait_all };
+ is(scalar(@$res), 2, 'two results');
+ is_deeply($res->[0], [ $raw, @x, undef ], '1st cb result');
+ is_deeply($res->[1], [ $raw, @x, undef ], '2st cb result');
+ like("@w", qr/\bHI\b/, 'die turned to warning');
}
if (1) {
^ permalink raw reply related [relevance 7%]
* [PATCH 0/3] git: propagate die from async callbacks
@ 2021-10-08 10:20 6% Eric Wong
2021-10-08 10:20 7% ` [PATCH 3/3] git: fatalize async callback errors by default Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-10-08 10:20 UTC (permalink / raw)
To: meta
This should help us find and notice -extindex (and perhaps
-mda/-watch/lei) bugs more quickly.
Eric Wong (3):
git: use async_wait_all everywhere
git: async_abort includes --batch-check requests
git: fatalize async callback errors by default
lib/PublicInbox/Daemon.pm | 2 ++
lib/PublicInbox/Gcf2Client.pm | 4 +--
lib/PublicInbox/Git.pm | 51 +++++++++++++++++++++-------------
lib/PublicInbox/GitAsyncCat.pm | 4 +--
lib/PublicInbox/LeiSearch.pm | 4 +--
lib/PublicInbox/LeiStore.pm | 2 +-
lib/PublicInbox/V2Writable.pm | 6 ++--
t/git.t | 28 +++++++++++++++++--
xt/cmp-msgstr.t | 2 +-
xt/cmp-msgview.t | 2 +-
xt/eml_check_limits.t | 2 +-
xt/eml_octet-stream.t | 2 +-
xt/git_async_cmp.t | 2 +-
xt/msgtime_cmp.t | 2 +-
xt/perf-msgview.t | 2 +-
xt/perf-obfuscate.t | 2 +-
16 files changed, 77 insertions(+), 40 deletions(-)
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-10-08 10:20 6% [PATCH 0/3] git: propagate die from async callbacks Eric Wong
2021-10-08 10:20 7% ` [PATCH 3/3] git: fatalize async callback errors by default Eric Wong
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).