From 02d1f3a06bc6900ad5c1b7c11b1fd38cbddef395 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Thu, 13 Feb 2025 15:59:32 -0800 Subject: [PATCH] runtime: respect GOTRACEBACK for user-triggered runtime panics The documentation for GOTRACEBACK says that "single" is the default where the stack trace for only a single routine is printed except that it prints all stack traces if: there is no current goroutine or the failure is internal to the run-time. In the runtime, there are two types of panics: throwTypeUser and throwTypeRuntime. The latter more clearly corresponds to a "failure [that] is internal to the run-time", while the former corresponds to a problem trigger due to a user mistake. Thus, a user-triggered panic (e.g., concurrent map access) should not result in a dump of all stack traces. Fixes #68019 Change-Id: I9b02f82535ddb9fd666f7158e2e4ee10f235646a Reviewed-on: https://go-review.googlesource.com/c/go/+/649535 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt Reviewed-by: Michael Knyszek --- src/runtime/runtime1.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index 43e4c142362..64ee4c8d2e9 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -39,7 +39,7 @@ func gotraceback() (level int32, all, crash bool) { gp := getg() t := atomic.Load(&traceback_cache) crash = t&tracebackCrash != 0 - all = gp.m.throwing >= throwTypeUser || t&tracebackAll != 0 + all = gp.m.throwing > throwTypeUser || t&tracebackAll != 0 if gp.m.traceback != 0 { level = int32(gp.m.traceback) } else if gp.m.throwing >= throwTypeRuntime {