Skip to content

Commit 82f09b7

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
os/exec: avoid leaking an exec.Cmd in TestWaitInterrupt
In CL 436655 I added a GODEBUG setting to this test process to verify that Wait is eventually called for every exec.Cmd before it becomes unreachable. However, the cmdHang test helpers in TestWaitInterrupt/Exit-hang and TestWaitInterrupt/SIGKILL-hang intentially leak a subprocess in order to simulate a leaky third-party program, as Go users might encounter in practical use. To avoid tripping over the leak check, we call Wait on the leaked subprocess in a background goroutine. Since we expect the process running cmdHang to exit before its subprocess does, the call to Wait should have no effect beyond suppressing the leak check. Fixes #57596. Updates #52580. Updates #50436. Change-Id: Ia4b88ea47fc6b605c27ca6d9d7669c874867a900 Reviewed-on: https://go-review.googlesource.com/c/go/+/460998 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent 0202ad0 commit 82f09b7

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/os/exec/exec_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ func cmdHang(args ...string) {
11821182
os.Exit(1)
11831183
}
11841184
fmt.Fprintf(os.Stderr, "%d: started %d: %v\n", pid, cmd.Process.Pid, cmd)
1185+
go cmd.Wait() // Release resources if cmd happens not to outlive this process.
11851186
}
11861187

11871188
if *exitOnInterrupt {

0 commit comments

Comments
 (0)