require PublicInbox::Listener;
use PublicInbox::EOFpipe;
use PublicInbox::Sigfd;
+use PublicInbox::Git;
use PublicInbox::GitAsyncCat;
our $SO_ACCEPTFILTER = 0x1000;
my @CMD;
# 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;
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
}
$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 ($) {
}
$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 ($) {
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"};
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 {
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) {