From cc795a01dcec7c97044b31571af88ac98310f2b3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 9 Dec 2021 12:51:29 -0500 Subject: [PATCH] testenv: kill subprocess if SIGQUIT doesn't do it This makes testenv.RunWithTimeout first attempt to SIGQUIT the subprocess to get a useful Go traceback, but if that doesn't work, it sends a SIGKILL instead to make sure we tear down the subprocess. This is potentially important for non-Go subprocesses. For #37405. Change-Id: I9e7e118dc5769ec3f45288a71658733bff30c9cd Reviewed-on: https://go-review.googlesource.com/c/go/+/370702 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor --- src/internal/testenv/testenv.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go index eeb7d65a9b..d7614b0706 100644 --- a/src/internal/testenv/testenv.go +++ b/src/internal/testenv/testenv.go @@ -346,6 +346,13 @@ func RunWithTimeout(t testing.TB, cmd *exec.Cmd) ([]byte, error) { case <-done: case <-time.After(time.Duration(scale) * time.Minute): p.Signal(Sigquit) + // If SIGQUIT doesn't do it after a little + // while, kill the process. + select { + case <-done: + case <-time.After(time.Duration(scale) * 30 * time.Second): + p.Signal(os.Kill) + } } }()