diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-12-12 08:52:59 +0300 |
---|---|---|
committer | GitLab <noreply@gitlab.com> | 2023-12-12 08:52:59 +0300 |
commit | 3fa4f66b3db439e87a080535d3899f1752286230 (patch) | |
tree | 0e50e50af2a0e7897b0d810aac104c482d1f755a | |
parent | e4c3cf70dac0562f2ddfb5f851cfe3f7f40c17f9 (diff) | |
parent | 1bfbf59b7873cc7bb571dfa8667a52ec11337966 (diff) |
Merge branch '5729-flaky-test-testcatfileobject-spawning_two_pipes_fails' into 'master'
catfile: Fix race condition in `CatfileObject`
Closes #5729
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/6578
Merged-by: Patrick Steinhardt <psteinhardt@gitlab.com>
Co-authored-by: Karthik Nayak <knayak@gitlab.com>
-rw-r--r-- | internal/git/gitpipe/catfile_object.go | 4 | ||||
-rw-r--r-- | internal/git/gitpipe/catfile_object_test.go | 1 |
2 files changed, 3 insertions, 2 deletions
diff --git a/internal/git/gitpipe/catfile_object.go b/internal/git/gitpipe/catfile_object.go index b809923d9..77c7fecd4 100644 --- a/internal/git/gitpipe/catfile_object.go +++ b/internal/git/gitpipe/catfile_object.go @@ -48,10 +48,10 @@ func CatfileObject( requestChan := make(chan catfileObjectRequest, 32) go func() { defer func() { - close(requestChan) if atomic.AddInt32(&queueRefcount, -1) == 0 { queueCleanup() } + close(requestChan) }() sendRequest := func(request catfileObjectRequest) bool { @@ -115,10 +115,10 @@ func CatfileObject( resultChan := make(chan CatfileObjectResult) go func() { defer func() { - close(resultChan) if atomic.AddInt32(&queueRefcount, -1) == 0 { queueCleanup() } + close(resultChan) }() sendResult := func(result CatfileObjectResult) bool { diff --git a/internal/git/gitpipe/catfile_object_test.go b/internal/git/gitpipe/catfile_object_test.go index b53d86aea..59872be13 100644 --- a/internal/git/gitpipe/catfile_object_test.go +++ b/internal/git/gitpipe/catfile_object_test.go @@ -243,6 +243,7 @@ func TestCatfileObject(t *testing.T) { _, err = io.Copy(io.Discard, it.Result()) require.NoError(t, err) require.False(t, it.Next()) + require.NoError(t, it.Err()) // Which means that the queue should now be unused, so we can again use it. _, err = CatfileObject(ctx, objectReader, NewRevisionIterator(ctx, input)) |