From 0fec65d281af8932ce8da946faa55884f2427cfc Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 29 Sep 2022 08:40:37 -0400 Subject: os/exec: add a GODEBUG setting to diagnose leaked processes Updates #52580. For #50436. Change-Id: I669f13863f1f85d576c3c94500b118e6989000eb Reviewed-on: https://go-review.googlesource.com/c/go/+/436655 Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Run-TryBot: Bryan Mills --- src/os/exec/exec_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/os/exec/exec_test.go') diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 822f606d66..13715fecac 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -38,6 +38,13 @@ import ( var haveUnexpectedFDs bool func init() { + godebug := os.Getenv("GODEBUG") + if godebug != "" { + godebug += "," + } + godebug += "execwait=2" + os.Setenv("GODEBUG", godebug) + if os.Getenv("GO_EXEC_TEST_PID") != "" { return } @@ -76,6 +83,14 @@ func TestMain(m *testing.M) { } } } + + if !testing.Short() { + // Run a couple of GC cycles to increase the odds of detecting + // process leaks using the finalizers installed by GODEBUG=execwait=2. + runtime.GC() + runtime.GC() + } + os.Exit(code) } -- cgit v1.3