From f85c40438fea862be03d2de4b58ed3afe7cfe033 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 24 May 2024 09:33:45 -0400 Subject: internal/runtime/exithook: make safe for concurrent os.Exit Real programs can call os.Exit concurrently from multiple goroutines. Make internal/runtime/exithook not crash in that case. The throw on panic also now runs in the deferred context, so that we will see the full stack trace that led to the panic. That should give us more visibility into the flaky failures on bugs #55167 and #56197 as well. Fixes #67631. Change-Id: Iefdf71b3a3b52a793ca88d89a9c270eb50ece094 Reviewed-on: https://go-review.googlesource.com/c/go/+/588235 Reviewed-by: Than McIntosh LUCI-TryBot-Result: Go LUCI Auto-Submit: Russ Cox --- src/runtime/testdata/testexithooks/testexithooks.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/runtime/testdata') diff --git a/src/runtime/testdata/testexithooks/testexithooks.go b/src/runtime/testdata/testexithooks/testexithooks.go index 151b5dc62b..d734aacb2d 100644 --- a/src/runtime/testdata/testexithooks/testexithooks.go +++ b/src/runtime/testdata/testexithooks/testexithooks.go @@ -6,8 +6,9 @@ package main import ( "flag" - "os" "internal/runtime/exithook" + "os" + "time" _ "unsafe" ) @@ -26,6 +27,8 @@ func main() { testPanics() case "callsexit": testHookCallsExit() + case "exit2": + testExit2() default: panic("unknown mode") } @@ -81,3 +84,12 @@ func testHookCallsExit() { exithook.Add(exithook.Hook{F: f3, RunOnFailure: true}) os.Exit(1) } + +func testExit2() { + f1 := func() { time.Sleep(100 * time.Millisecond) } + exithook.Add(exithook.Hook{F: f1}) + for range 10 { + go os.Exit(0) + } + os.Exit(0) +} -- cgit v1.3