From ff7ecb4efc2f754709ec018ae822fb411fcfa5a9 Mon Sep 17 00:00:00 2001 From: Basavaraj PB Date: Tue, 10 Mar 2026 23:28:14 +0530 Subject: [PATCH] os/exec: document that Cmd.Wait must not be called concurrently Clarify in the Wait documentation that it must not be called concurrently from multiple goroutines. Also note that a custom Cmd.Cancel function should not call Wait because Cancel may be invoked by watchCtx in a separate goroutine. Fixes #78046 Change-Id: I5c0ebc41bd3c39c78f3b37539c59cdfedfd90e72 Reviewed-on: https://go-review.googlesource.com/c/go/+/753602 Reviewed-by: Ian Lance Taylor Reviewed-by: Carlos Amedee Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Freeman --- src/os/exec/exec.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index e5bf97a188..26ddfe633c 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -929,6 +929,9 @@ func (e *ExitError) Error() string { // If any of c.Stdin, c.Stdout or c.Stderr are not an [*os.File], Wait also waits // for the respective I/O loop copying to or from the process to complete. // +// Wait must not be called concurrently from multiple goroutines. +// A custom Cmd.Cancel function should not call Wait. +// // Wait releases any resources associated with the [Cmd]. func (c *Cmd) Wait() error { if c.Process == nil {