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>2020-07-20 11:23:08 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-07-20 11:41:54 +0300
commitbeb98d66c8dba648262b2da60a95954e3657a913 (patch)
treee6e8eedabca3ed2e87cbb9b8989aabeb15c16811
parent893137c05e065ab96edd21af1a5ad8f6745b4a08 (diff)
praefect: Fix service registration after start
It's not allowed to register any more services with a GRPC server after it's been started already. But due to a race, we may do exactly that when registering new mocked SmartHTTP servers: `NewServerWithHealth()` not only creates a new GRPC server with the health service registered, but already starts it. As we still need to register the SmartHTTP server afterwards, we're thus racing against the server's `Serve()` Goroutine. Fix this race by assembling the server manually before calling `Serve()` on it.
-rw-r--r--internal/praefect/server_test.go17
1 files changed, 13 insertions, 4 deletions
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index f70e481fa..f97bf0409 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -38,6 +38,7 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/version"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
+ "google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
)
@@ -743,12 +744,20 @@ func (m *mockSmartHTTP) Called(method string) int {
func newGrpcServer(t *testing.T, srv gitalypb.SmartHTTPServiceServer) (string, *grpc.Server) {
socketPath := testhelper.GetTemporaryGitalySocketFileName()
- grpcSrv, _ := testhelper.NewServerWithHealth(t, socketPath)
+ listener, err := net.Listen("unix", socketPath)
+ require.NoError(t, err)
+
+ grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
+
+ healthSrvr := health.NewServer()
+ grpc_health_v1.RegisterHealthServer(grpcServer, healthSrvr)
+ healthSrvr.SetServingStatus("", grpc_health_v1.HealthCheckResponse_SERVING)
+ gitalypb.RegisterSmartHTTPServiceServer(grpcServer, srv)
+ reflection.Register(grpcServer)
- gitalypb.RegisterSmartHTTPServiceServer(grpcSrv, srv)
- reflection.Register(grpcSrv)
+ go grpcServer.Serve(listener)
- return socketPath, grpcSrv
+ return socketPath, grpcServer
}
func TestProxyWrites(t *testing.T) {