Skip to content

[data-race] Setting the global GRPC logger while starting the server in another test #448

@liran-funaro

Description

@liran-funaro

We init the GRPC logger (grpclog.SetLoggerV2) every time we update the logger config from YAML.
But other tests may use this logger as it is a global variable.


  • Cause: grpclog.SetLoggerV2() is not thread-safe; multiple goroutines could call it concurrently during package initialization
  • Manifestation: Concurrent writes to gRPC's global logger state when multiple packages import flogging simultaneously


==================
WARNING: DATA RACE
Write at 0x0000031a8010 by goroutine 55:
  google.golang.org/grpc/grpclog.SetLoggerV2()
      /home/runner/go/pkg/mod/google.golang.org/grpc@v1.78.0/grpclog/loggerv2.go:39 +0x51b
  github.com/hyperledger/fabric-x-committer/cmd/config.ReadYamlAndSetupLogging()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/config/app_config.go:95 +0x26e
  github.com/hyperledger/fabric-x-committer/cmd/config.ReadSidecarYamlAndSetupLogging()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/config/app_config.go:36 +0x184
  github.com/hyperledger/fabric-x-committer/cmd/config.SidecarCMD.func1()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/config/cmd.go:66 +0x65
  github.com/spf13/cobra.(*Command).execute()
      /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1015 +0x1190
  github.com/spf13/cobra.(*Command).ExecuteC()
      /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1148 +0x797
  github.com/spf13/cobra.(*Command).ExecuteContextC()
      /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.10.2/command.go:1080 +0x2b2
  github.com/hyperledger/fabric-x-committer/cmd/config.UnitTestRunner.func3()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/config/cobra_test_exports.go:138 +0x25f

Previous read at 0x0000031a8010 by goroutine 21:
  google.golang.org/grpc/grpclog.InfoDepth()
      /home/runner/go/pkg/mod/google.golang.org/grpc@v1.78.0/grpclog/grpclog.go:141 +0x8a
  google.golang.org/grpc/grpclog.(*componentData).InfoDepth()
      /home/runner/go/pkg/mod/google.golang.org/grpc@v1.78.0/grpclog/component.go:34 +0x16c
  google.golang.org/grpc/internal/channelz.AddTraceEvent()
      /home/runner/go/pkg/mod/google.golang.org/grpc@v1.78.0/internal/channelz/trace.go:200 +0x32e
  google.golang.org/grpc/internal/channelz.Info()
      /home/runner/go/pkg/mod/google.golang.org/grpc@v1.78.0/internal/channelz/logging.go:31 +0x10d
  google.golang.org/grpc.(*Server).Serve()
      /home/runner/go/pkg/mod/google.golang.org/grpc@v1.78.0/server.go:913 +0x6ac
  github.com/hyperledger/fabric-x-committer/utils/test.RunGrpcServerForTest.func1()
      /home/runner/work/fabric-x-committer/fabric-x-committer/utils/test/utils.go:131 +0x93
  sync.(*WaitGroup).Go.func1()
      /opt/hostedtoolcache/go/1.26.1/x64/src/sync/waitgroup.go:258 +0x5d

Goroutine 55 (running) created at:
  github.com/hyperledger/fabric-x-committer/cmd/config.UnitTestRunner()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/config/cobra_test_exports.go:134 +0xc8a
  github.com/hyperledger/fabric-x-committer/cmd/committer.TestCommitterCMD.func2.1()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/committer/main_test.go:96 +0x10c
  testing.tRunner()
      /opt/hostedtoolcache/go/1.26.1/x64/src/testing/testing.go:2036 +0x21c
  testing.(*T).Run.gowrap1()
      /opt/hostedtoolcache/go/1.26.1/x64/src/testing/testing.go:2101 +0x38

Goroutine 21 (running) created at:
  sync.(*WaitGroup).Go()
      /opt/hostedtoolcache/go/1.26.1/x64/src/sync/waitgroup.go:238 +0x86
  github.com/hyperledger/fabric-x-committer/utils/test.RunGrpcServerForTest()
      /home/runner/work/fabric-x-committer/fabric-x-committer/utils/test/utils.go:129 +0x630
  github.com/hyperledger/fabric-x-committer/utils/test.StartGrpcServersWithConfigForTest()
      /home/runner/work/fabric-x-committer/fabric-x-committer/utils/test/utils.go:170 +0x18d
  github.com/hyperledger/fabric-x-committer/utils/test.StartGrpcServersForTest()
      /home/runner/work/fabric-x-committer/fabric-x-committer/utils/test/utils.go:155 +0x47b
  github.com/hyperledger/fabric-x-committer/mock.StartMockCoordinatorService()
      /home/runner/work/fabric-x-committer/fabric-x-committer/mock/test_exports.go:67 +0x1a4
  github.com/hyperledger/fabric-x-committer/cmd/config.StartDefaultSystem()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/config/cobra_test_exports.go:52 +0x2de
  github.com/hyperledger/fabric-x-committer/cmd/committer.TestCommitterCMD()
      /home/runner/work/fabric-x-committer/fabric-x-committer/cmd/committer/main_test.go:26 +0x9b
  testing.tRunner()
      /opt/hostedtoolcache/go/1.26.1/x64/src/testing/testing.go:2036 +0x21c
  testing.(*T).Run.gowrap1()
      /opt/hostedtoolcache/go/1.26.1/x64/src/testing/testing.go:2101 +0x38
==================

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions