Skip to content

Commit 2088083

Browse files
findleyrgopherbot
authored andcommitted
internal/gocommand: add more debug info for hanging go commands
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]>
1 parent f1a3b12 commit 2088083

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

internal/gocommand/invoke.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) (err error) {
358358
}
359359
}
360360

361+
startTime := time.Now()
361362
err = cmd.Start()
362363
if stdoutW != nil {
363364
// The child process has inherited the pipe file,
@@ -384,7 +385,7 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) (err error) {
384385
case err := <-resChan:
385386
return err
386387
case <-timer.C:
387-
HandleHangingGoCommand(cmd.Process)
388+
HandleHangingGoCommand(startTime, cmd)
388389
case <-ctx.Done():
389390
}
390391
} else {
@@ -418,7 +419,7 @@ func runCmdContext(ctx context.Context, cmd *exec.Cmd) (err error) {
418419
return <-resChan
419420
}
420421

421-
func HandleHangingGoCommand(proc *os.Process) {
422+
func HandleHangingGoCommand(start time.Time, cmd *exec.Cmd) {
422423
switch runtime.GOOS {
423424
case "linux", "darwin", "freebsd", "netbsd":
424425
fmt.Fprintln(os.Stderr, `DETECTED A HANGING GO COMMAND
@@ -451,7 +452,7 @@ See golang/go#54461 for more details.`)
451452
panic(fmt.Sprintf("running %s: %v", listFiles, err))
452453
}
453454
}
454-
panic(fmt.Sprintf("detected hanging go command (pid %d): see golang/go#54461 for more details", proc.Pid))
455+
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))
455456
}
456457

457458
func cmdDebugStr(cmd *exec.Cmd) string {

0 commit comments

Comments
 (0)