From e270169c1301135de1518f1c3f263a0b8d5759f6 Mon Sep 17 00:00:00 2001 From: Dongjun Na Date: Tue, 17 Dec 2024 22:06:57 +0900 Subject: [PATCH] Add -race Flag to GitHub Action and Fix Data Race in CreateTailscaleNodesInUser (#2038) * Add -race flag to Makefile and integration tests; fix data race in CreateTailscaleNodesInUser * Fix data race in ExecuteCommand by using local buffers and mutex Signed-off-by: Dongjun Na * lint Signed-off-by: Dongjun Na --------- Signed-off-by: Dongjun Na --- Makefile | 4 ++-- integration/dockertestutil/execute.go | 3 +-- integration/scenario.go | 4 ++++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5b09147d..25fa1c67 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ build: dev: lint test build test: - gotestsum -- -short -coverprofile=coverage.out ./... + gotestsum -- -short -race -coverprofile=coverage.out ./... test_integration: docker run \ @@ -33,7 +33,7 @@ test_integration: -v /var/run/docker.sock:/var/run/docker.sock \ -v $$PWD/control_logs:/tmp/control \ golang:1 \ - go run gotest.tools/gotestsum@latest -- -failfast ./... -timeout 120m -parallel 8 + go run gotest.tools/gotestsum@latest -- -race -failfast ./... -timeout 120m -parallel 8 lint: golangci-lint run --fix --timeout 10m diff --git a/integration/dockertestutil/execute.go b/integration/dockertestutil/execute.go index 9e16f366..078b3bc2 100644 --- a/integration/dockertestutil/execute.go +++ b/integration/dockertestutil/execute.go @@ -25,7 +25,6 @@ type ExecuteCommandOption func(*ExecuteCommandConfig) error func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption { return ExecuteCommandOption(func(conf *ExecuteCommandConfig) error { conf.timeout = timeout - return nil }) } @@ -67,6 +66,7 @@ func ExecuteCommand( StdErr: &stderr, }, ) + resultChan <- result{exitCode, err} }() @@ -88,7 +88,6 @@ func ExecuteCommand( return stdout.String(), stderr.String(), nil case <-time.After(execConfig.timeout): - return stdout.String(), stderr.String(), fmt.Errorf("command failed, stderr: %s: %w", stderr.String(), ErrDockertestCommandTimeout) } } diff --git a/integration/scenario.go b/integration/scenario.go index 99a25647..987b8dbe 100644 --- a/integration/scenario.go +++ b/integration/scenario.go @@ -372,18 +372,22 @@ func (s *Scenario) CreateTailscaleNodesInUser( cert := headscale.GetCert() hostname := headscale.GetHostname() + s.mu.Lock() opts = append(opts, tsic.WithCACert(cert), tsic.WithHeadscaleName(hostname), ) + s.mu.Unlock() user.createWaitGroup.Go(func() error { + s.mu.Lock() tsClient, err := tsic.New( s.pool, version, s.network, opts..., ) + s.mu.Unlock() if err != nil { return fmt.Errorf( "failed to create tailscale (%s) node: %w",