From 36facaa1f9a24175f0fbe4fe5f479bbfb67d05e9 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 13 Sep 2023 09:58:17 -0400 Subject: os/exec: avoid writing to Cmd.Path in Cmd.Start on Windows Fixes #62596. Change-Id: I9003318ac1c4e3036f32383e62e9ba08c383d5c2 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-race,gotip-windows-amd64-race,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/527820 Reviewed-by: Ian Lance Taylor Auto-Submit: Bryan Mills LUCI-TryBot-Result: Go LUCI --- src/os/exec/exec_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/os/exec/exec_test.go') diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 9783a133ba..71a00494ad 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -1819,3 +1819,19 @@ func TestConcurrentExec(t *testing.T) { cancel() hangs.Wait() } + +// TestPathRace tests that [Cmd.String] can be called concurrently +// with [Cmd.Start]. +func TestPathRace(t *testing.T) { + cmd := helperCommand(t, "exit", "0") + + done := make(chan struct{}) + go func() { + out, err := cmd.CombinedOutput() + t.Logf("%v: %v\n%s", cmd, err, out) + close(done) + }() + + t.Logf("running in background: %v", cmd) + <-done +} -- cgit v1.3