aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2024-05-24 09:33:45 -0400
committerGopher Robot <gobot@golang.org>2024-05-24 16:41:13 +0000
commitf85c40438fea862be03d2de4b58ed3afe7cfe033 (patch)
tree199325218768f9bd674f77dcfe9f3312ecff164f /src/runtime/testdata
parent378c48df3b485da1ed287f59e5d1f59ad232e554 (diff)
downloadgo-f85c40438fea862be03d2de4b58ed3afe7cfe033.tar.xz
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 <thanm@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/testdata')
-rw-r--r--src/runtime/testdata/testexithooks/testexithooks.go14
1 files changed, 13 insertions, 1 deletions
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)
+}