Skip to content

Commit 82c8a38

Browse files
Bryan C. Millsgopherbot
authored andcommitted
internal/gocommand: set a WaitDelay (when available) on commands
Fixes golang/go#59541. Change-Id: I8b88f369c5b8d41f3dc2f1c38e0e736279046c6d Reviewed-on: https://go-review.googlesource.com/c/tools/+/484743 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Commit-Queue: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent e286d22 commit 82c8a38

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/gocommand/invoke.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"io"
1414
"log"
1515
"os"
16+
"reflect"
1617
"regexp"
1718
"runtime"
1819
"strconv"
@@ -216,6 +217,18 @@ func (i *Invocation) run(ctx context.Context, stdout, stderr io.Writer) error {
216217
cmd := exec.Command("go", goArgs...)
217218
cmd.Stdout = stdout
218219
cmd.Stderr = stderr
220+
221+
// cmd.WaitDelay was added only in go1.20 (see #50436).
222+
if waitDelay := reflect.ValueOf(cmd).Elem().FieldByName("WaitDelay"); waitDelay.IsValid() {
223+
// https://go.dev/issue/59541: don't wait forever copying stderr
224+
// after the command has exited.
225+
// After CL 484741 we copy stdout manually, so we we'll stop reading that as
226+
// soon as ctx is done. However, we also don't want to wait around forever
227+
// for stderr. Give a much-longer-than-reasonable delay and then assume that
228+
// something has wedged in the kernel or runtime.
229+
waitDelay.Set(reflect.ValueOf(30 * time.Second))
230+
}
231+
219232
// On darwin the cwd gets resolved to the real path, which breaks anything that
220233
// expects the working directory to keep the original path, including the
221234
// go command when dealing with modules.
@@ -230,6 +243,7 @@ func (i *Invocation) run(ctx context.Context, stdout, stderr io.Writer) error {
230243
cmd.Env = append(cmd.Env, "PWD="+i.WorkingDir)
231244
cmd.Dir = i.WorkingDir
232245
}
246+
233247
defer func(start time.Time) { log("%s for %v", time.Since(start), cmdDebugStr(cmd)) }(time.Now())
234248

235249
return runCmdContext(ctx, cmd)

0 commit comments

Comments
 (0)