]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: async: loop inflight checks for nested callbacks
authorEric Wong <e@80x24.org>
Fri, 16 Oct 2020 06:59:34 +0000 (06:59 +0000)
committerEric Wong <e@80x24.org>
Fri, 16 Oct 2020 17:15:26 +0000 (17:15 +0000)
We need to loop the inflight check for nested callback
invocations to ensure we don't clog the pipe that feeds
`git cat-file'.

This bug was obscured by the fact that we're already
accounting for 64-char git OIDs with SHA-256 in the
pipe space calculation; perhaps we shouldn't do that.

lib/PublicInbox/Git.pm

index eb5de159d2e6db16122c43b7c665f62c6d39e754..e3a2bcb8df8f43d5c3e421852ded73dde2c9a9e2 100644 (file)
@@ -275,7 +275,7 @@ sub check_async_begin ($) {
 sub check_async ($$$$) {
        my ($self, $oid, $cb, $arg) = @_;
        my $inflight_c = $self->{inflight_c} // check_async_begin($self);
-       if (scalar(@$inflight_c) >= MAX_INFLIGHT) {
+       while (scalar(@$inflight_c) >= MAX_INFLIGHT) {
                check_async_step($self, $inflight_c);
        }
        print { $self->{out_c} } $oid, "\n" or fail($self, "write error: $!");
@@ -420,10 +420,9 @@ sub cat_async_begin {
 sub cat_async ($$$;$) {
        my ($self, $oid, $cb, $arg) = @_;
        my $inflight = $self->{inflight} // cat_async_begin($self);
-       if (scalar(@$inflight) >= MAX_INFLIGHT) {
+       while (scalar(@$inflight) >= MAX_INFLIGHT) {
                cat_async_step($self, $inflight);
        }
-
        print { $self->{out} } $oid, "\n" or fail($self, "write error: $!");
        push(@$inflight, $oid, $cb, $arg);
 }