diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2023-10-14 18:55:07 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <brad@danga.com> | 2023-10-14 19:12:43 -0700 |
| commit | e89927de2b86fa298c80cb115033f74e39ad4eaf (patch) | |
| tree | 272ed5b8f147bca2b383dab70dce43cd92e61742 | |
| parent | 18e2936d25a33b1cb8025172495cabb917e2d7ad (diff) | |
| download | tailscale-e89927de2b86fa298c80cb115033f74e39ad4eaf.tar.xz tailscale-e89927de2b86fa298c80cb115033f74e39ad4eaf.zip | |
tsnet: fix data race in TestFallbackTCPHandler
Fixes #9805
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
| -rw-r--r-- | tsnet/tsnet_test.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/tsnet/tsnet_test.go b/tsnet/tsnet_test.go index 0d1689683..9d98db2fd 100644 --- a/tsnet/tsnet_test.go +++ b/tsnet/tsnet_test.go @@ -26,6 +26,7 @@ import ( "reflect" "strings" "sync" + "sync/atomic" "testing" "time" @@ -652,23 +653,23 @@ func TestFallbackTCPHandler(t *testing.T) { } t.Logf("ping success: %#+v", res) - s1TcpConnCount := 0 + var s1TcpConnCount atomic.Int32 deregister := s1.RegisterFallbackTCPHandler(func(src, dst netip.AddrPort) (handler func(net.Conn), intercept bool) { - s1TcpConnCount++ + s1TcpConnCount.Add(1) return nil, false }) - if _, err = s2.Dial(ctx, "tcp", fmt.Sprintf("%s:8081", s1ip)); err == nil { + if _, err := s2.Dial(ctx, "tcp", fmt.Sprintf("%s:8081", s1ip)); err == nil { t.Fatal("Expected dial error because fallback handler did not intercept") } - if s1TcpConnCount != 1 { - t.Errorf("s1TcpConnCount = %d, want %d", s1TcpConnCount, 1) + if got := s1TcpConnCount.Load(); got != 1 { + t.Errorf("s1TcpConnCount = %d, want %d", got, 1) } deregister() - if _, err = s2.Dial(ctx, "tcp", fmt.Sprintf("%s:8081", s1ip)); err == nil { + if _, err := s2.Dial(ctx, "tcp", fmt.Sprintf("%s:8081", s1ip)); err == nil { t.Fatal("Expected dial error because nothing would intercept") } - if s1TcpConnCount != 1 { - t.Errorf("s1TcpConnCount = %d, want %d", s1TcpConnCount, 1) + if got := s1TcpConnCount.Load(); got != 1 { + t.Errorf("s1TcpConnCount = %d, want %d", got, 1) } } |
