Skip to content

Commit

Permalink
internal/gocommand: add more debug info for hanging go commands
Browse files Browse the repository at this point in the history
For golang/go#54461

Change-Id: I2de5a10673345342e30e50cb39359c10e8eb7319
Reviewed-on: https://go-review.googlesource.com/c/tools/+/589956
Auto-Submit: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Jun 4, 2024
1 parent f1a3b12 commit 2088083
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/gocommand/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) (err error) {
}
}

startTime := time.Now()
err = cmd.Start()
if stdoutW != nil {
// The child process has inherited the pipe file,
Expand All @@ -384,7 +385,7 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) (err error) {
case err := <-resChan:
return err
case <-timer.C:
HandleHangingGoCommand(cmd.Process)
HandleHangingGoCommand(startTime, cmd)
case <-ctx.Done():
}
} else {
Expand Down Expand Up @@ -418,7 +419,7 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) (err error) {
return <-resChan
}

func HandleHangingGoCommand(proc *os.Process) {
func HandleHangingGoCommand(start time.Time, cmd *exec.Cmd) {
switch runtime.GOOS {
case "linux", "darwin", "freebsd", "netbsd":
fmt.Fprintln(os.Stderr, `DETECTED A HANGING GO COMMAND
Expand Down Expand Up @@ -451,7 +452,7 @@ See golang/go#54461 for more details.`)
panic(fmt.Sprintf("running %s: %v", listFiles, err))
}
}
panic(fmt.Sprintf("detected hanging go command (pid %d): see golang/go#54461 for more details", proc.Pid))
panic(fmt.Sprintf("detected hanging go command (golang/go#54461); waited %s\n\tcommand:%s\n\tpid:%d", time.Since(start), cmd, cmd.Process.Pid))
}

func cmdDebugStr(cmd *exec.Cmd) string {
Expand Down

0 comments on commit 2088083

Please sign in to comment.