Skip to content

Commit cb7c137

Browse files
committed
internal/gocommand: more tweaks to DebugHangingGoCommands
As suggested by bcmills, this change increases the time between SIGINT and SIGKILL to 5s (was 1s), and also suppresses the process dump if SIGKILL returned "already done". Updates golang/go#57999 Updates golang/go#54461 Change-Id: Ie0e55a69d3bbfb4224e5f4ea272c7c2f3210e342 Reviewed-on: https://go-review.googlesource.com/c/tools/+/483215 Run-TryBot: Alan Donovan <[email protected]> gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent b93774a commit cb7c137

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

internal/gocommand/invoke.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package gocommand
88
import (
99
"bytes"
1010
"context"
11+
"errors"
1112
"fmt"
1213
"io"
1314
"log"
@@ -253,7 +254,8 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) error {
253254

254255
// If we're interested in debugging hanging Go commands, stop waiting after a
255256
// minute and panic with interesting information.
256-
if DebugHangingGoCommands {
257+
debug := DebugHangingGoCommands
258+
if debug {
257259
select {
258260
case err := <-resChan:
259261
return err
@@ -274,19 +276,25 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) error {
274276
select {
275277
case err := <-resChan:
276278
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.)
278282
}
279283

280284
// Didn't shut down in response to interrupt. Kill it hard.
281285
// TODO(rfindley): per advice from bcmills@, it may be better to send SIGQUIT
282286
// 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+
}
286294
}
287295

288296
// See above: don't wait indefinitely if we're debugging hanging Go commands.
289-
if DebugHangingGoCommands {
297+
if debug {
290298
select {
291299
case err := <-resChan:
292300
return err

0 commit comments

Comments
 (0)