Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-29 15:06:04 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-30 08:47:41 +0300
commit15fdeb41ea6b004e1afe62541ef9440946c3dec7 (patch)
treed7ecf8ce632fb35c029b46c5f5aaf372889319d9
parente976d7cf390c5e6c9287036130a84074a112ac34 (diff)
smarthttp: Fix test race where response buffer may not be filledpks-smarthttp-refactor-flaky-gitconfig-test
We have observed a racy test in production where fetching a hidden ref via `PostUploadPack` isn't failing in the way we expect it to. While the error code is there and the RPC call itself has failed, the response buffer we see is completely empty. This race can easily be caused by our testing infrastructure though: we use `makePostUploadPackWithSidechannelRequest()` to set up a sidechannel and then copy the sidechannel data via a separate Goroutine. In case we see an error though while handling the sidechannel (which is the case: we expect to fail fetching the hidden ref), we don't synchronize with the Goroutine copying the response. Fix this race by properly synchronizing the Goroutine via a wait group.
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack_test.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go
index a7b9e4c61..123b0a816 100644
--- a/internal/gitaly/service/smarthttp/upload_pack_test.go
+++ b/internal/gitaly/service/smarthttp/upload_pack_test.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"path/filepath"
+ "sync"
"testing"
"github.com/prometheus/client_golang/prometheus"
@@ -588,8 +589,13 @@ func makePostUploadPackWithSidechannelRequest(ctx context.Context, t *testing.T,
responseBuffer := &bytes.Buffer{}
ctxOut, waiter := sidechannel.RegisterSidechannel(ctx, registry, func(sideConn *sidechannel.ClientConn) error {
+ var wg sync.WaitGroup
+ defer wg.Wait()
+
+ wg.Add(1)
errC := make(chan error, 1)
go func() {
+ defer wg.Done()
_, err := io.Copy(responseBuffer, sideConn)
errC <- err
}()