Skip to content

Fix data race in finder

Mikhail Mazurskiy requested to merge ash2k/fix-data-race into master

Introduced in !1067 (merged).

INFO: From Testing //cmd/kas/kasapp:kasapp_test:
==================== Test output for //cmd/kas/kasapp:kasapp_test:
==================
WARNING: DATA RACE
Read at 0x00c000414210 by goroutine 85:
  runtime.mapdelete()
      GOROOT/src/runtime/map.go:695 +0x47c
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).stopAllConnectionAttempts()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:326 +0x570
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).Find()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:146 +0x534
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.TestTunnelFinder_StopTryingAbsentKasUrl()
      cmd/kas/kasapp/router_kas_tunnel_finder_test.go:175 +0x59c
  testing.tRunner()
      GOROOT/src/testing/testing.go:1576 +0x188
  testing.(*T).Run.func1()
      GOROOT/src/testing/testing.go:1629 +0x40

Previous write at 0x00c000414210 by goroutine 447:
  runtime.mapassign_faststr()
      GOROOT/src/runtime/map_faststr.go:203 +0x42c
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).maybeStopTrying()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:313 +0x1dc
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).tryKasAsync.func1.1()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:208 +0x74
  runtime.deferreturn()
      GOROOT/src/runtime/panic.go:476 +0x30
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/retry.PollWithBackoff()
      internal/tool/retry/retry.go:80 +0x1e8
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).tryKasAsync()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:199 +0x20c
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).tryKasLocked.func1()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:192 +0x68
  k8s.io/apimachinery/pkg/util/wait.(*Group).Start.func1()
      external/io_k8s_apimachinery/pkg/util/wait/wait.go:72 +0x6c

Goroutine 85 (running) created at:
  testing.(*T).Run()
      GOROOT/src/testing/testing.go:1629 +0x5e4
  testing.runTests.func1()
      GOROOT/src/testing/testing.go:2036 +0x80
  testing.tRunner()
      GOROOT/src/testing/testing.go:1576 +0x188
  testing.runTests()
      GOROOT/src/testing/testing.go:2034 +0x700
  testing.(*M).Run()
      GOROOT/src/testing/testing.go:1906 +0x950
  main.main()
      bazel-out/darwin_arm64-fastbuild/bin/cmd/kas/kasapp/kasapp_test_/testmain.go:170 +0x48c

Goroutine 447 (finished) created at:
  k8s.io/apimachinery/pkg/util/wait.(*Group).Start()
      external/io_k8s_apimachinery/pkg/util/wait/wait.go:70 +0xcc
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).tryKasLocked()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:191 +0x1e8
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).tryNextKas()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:180 +0x150
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.(*tunnelFinder).Find()
      cmd/kas/kasapp/router_kas_tunnel_finder.go:158 +0x4fc
  gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/cmd/kas/kasapp.TestTunnelFinder_StopTryingAbsentKasUrl()
      cmd/kas/kasapp/router_kas_tunnel_finder_test.go:175 +0x59c
  testing.tRunner()
      GOROOT/src/testing/testing.go:1576 +0x188
  testing.(*T).Run.func1()
      GOROOT/src/testing/testing.go:1629 +0x40
==================
--- FAIL: TestTunnelFinder_StopTryingAbsentKasUrl (0.01s)
    logger.go:130: 2023-08-10T04:36:47.634Z     DEBUG   Trying tunnel   {"kas_url": "grpc://self"}
    logger.go:130: 2023-08-10T04:36:47.645Z     DEBUG   Trying tunnel   {"kas_url": "grpc://pipe"}
    testing.go:1446: race detected during execution of test
--- FAIL: TestTunnelFinder_PollStartsGoroutineForEachUrl (0.02s)
    logger.go:130: 2023-08-10T04:36:47.634Z     DEBUG   Trying tunnel   {"kas_url": "grpc://self"}
    logger.go:130: 2023-08-10T04:36:47.645Z     DEBUG   Trying tunnel   {"kas_url": "grpc://pipe"}
    logger.go:130: 2023-08-10T04:36:47.656Z     DEBUG   Trying tunnel   {"kas_url": "grpc://pipe2"}
    testing.go:1446: race detected during execution of test
FAIL

Merge request reports

Loading