@@ -8,6 +8,7 @@ package gocommand
8
8
import (
9
9
"bytes"
10
10
"context"
11
+ "errors"
11
12
"fmt"
12
13
"io"
13
14
"log"
@@ -253,7 +254,8 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) error {
253
254
254
255
// If we're interested in debugging hanging Go commands, stop waiting after a
255
256
// minute and panic with interesting information.
256
- if DebugHangingGoCommands {
257
+ debug := DebugHangingGoCommands
258
+ if debug {
257
259
select {
258
260
case err := <- resChan :
259
261
return err
@@ -274,19 +276,25 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) error {
274
276
select {
275
277
case err := <- resChan :
276
278
return err
277
- case <- time .After (time .Second ):
279
+ case <- time .After (5 * time .Second ):
280
+ // (We used to wait only 1s but this proved
281
+ // fragile on loaded builder machines.)
278
282
}
279
283
280
284
// Didn't shut down in response to interrupt. Kill it hard.
281
285
// TODO(rfindley): per advice from bcmills@, it may be better to send SIGQUIT
282
286
// on certain platforms, such as unix.
283
- if err := cmd .Process .Kill (); err != nil && DebugHangingGoCommands {
284
- // Don't panic here as this reliably fails on windows with EINVAL.
285
- log .Printf ("error killing the Go command: %v" , err )
287
+ if err := cmd .Process .Kill (); err != nil && debug {
288
+ if errors .Is (err , os .ErrProcessDone ) {
289
+ debug = false // no need to dump the process tree
290
+ } else {
291
+ // Don't panic here as this reliably fails on windows with EINVAL.
292
+ log .Printf ("error killing the Go command: %v" , err )
293
+ }
286
294
}
287
295
288
296
// See above: don't wait indefinitely if we're debugging hanging Go commands.
289
- if DebugHangingGoCommands {
297
+ if debug {
290
298
select {
291
299
case err := <- resChan :
292
300
return err
0 commit comments