Skip to content

Commit ece19c8

Browse files
pohlyonsi
authored andcommitted
ginkgo: fix data race
Write at 0x00c000368528 by goroutine 25: os/exec.(*Cmd).Wait() os/exec/exec.go:926 +0x1a4 github.com/onsi/ginkgo/v2/ginkgo/internal.runParallel.func2() github.com/onsi/ginkgo/[email protected]/ginkgo/internal/run.go:231 +0x37 Previous read at 0x00c000368528 by goroutine 96714: github.com/onsi/ginkgo/v2/ginkgo/internal.runParallel.func1() github.com/onsi/ginkgo/[email protected]/ginkgo/internal/run.go:228 +0x3b github.com/onsi/ginkgo/v2/internal/parallel_support.(*ServerHandler).procIsAlive() github.com/onsi/ginkgo/[email protected]/internal/parallel_support/server_handler.go:133 +0x121 The problem is that cmd.ProcessState is not thread-safe. The solution is an atomic bool which gets checked instead and which is written once when the goroutine waiting for the command has determined that the command has exited.
1 parent 9a84c21 commit ece19c8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎ginkgo/internal/run.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"regexp"
1111
"strings"
12+
"sync/atomic"
1213
"syscall"
1314
"time"
1415

@@ -224,8 +225,9 @@ func runParallel(suite TestSuite, ginkgoConfig types.SuiteConfig, reporterConfig
224225
args = append(args, additionalArgs...)
225226

226227
cmd, buf := buildAndStartCommand(suite, args, false)
228+
var exited atomic.Bool
227229
procOutput[proc-1] = buf
228-
server.RegisterAlive(proc, func() bool { return cmd.ProcessState == nil || !cmd.ProcessState.Exited() })
230+
server.RegisterAlive(proc, func() bool { return !exited.Load() })
229231

230232
go func() {
231233
cmd.Wait()
@@ -234,6 +236,7 @@ func runParallel(suite TestSuite, ginkgoConfig types.SuiteConfig, reporterConfig
234236
passed: (exitStatus == 0) || (exitStatus == types.GINKGO_FOCUS_EXIT_CODE),
235237
hasProgrammaticFocus: exitStatus == types.GINKGO_FOCUS_EXIT_CODE,
236238
}
239+
exited.Store(true)
237240
}()
238241
}
239242

0 commit comments

Comments
 (0)