]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: do not print recovered when double panic with the same value
authorYoulin Feng <fengyoulin@live.com>
Wed, 29 Oct 2025 05:11:48 +0000 (13:11 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 18 Nov 2025 15:22:50 +0000 (07:22 -0800)
Show the "[recovered, repanicked]" message only when it is repanicked
after recovered. For the duplicated panics that not recovered, do not
show this message.

Fixes #76099

Change-Id: I87282022ebe44c6f6efbe3239218be4a2a7b1104
Reviewed-on: https://go-review.googlesource.com/c/go/+/716020
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>

src/runtime/crash_test.go
src/runtime/panic.go
src/runtime/testdata/testprog/crash.go

index 2b8ca549ad84f214446af09ab1f518a3ff47bf9f..00e67aeca0c46e3a7d3befda6dc73c2739190ca0 100644 (file)
@@ -413,6 +413,15 @@ func TestRepanickedPanicSandwich(t *testing.T) {
        }
 }
 
+func TestDoublePanicWithSameValue(t *testing.T) {
+       output := runTestProg(t, "testprog", "DoublePanicWithSameValue")
+       want := `panic: message
+`
+       if !strings.HasPrefix(output, want) {
+               t.Fatalf("output does not start with %q:\n%s", want, output)
+       }
+}
+
 func TestGoexitCrash(t *testing.T) {
        // External linking brings in cgo, causing deadlock detection not working.
        testenv.MustInternalLink(t, deadlockBuildTypes)
index 3c967a29997da39a7bbb04bb1f1644e31820e69c..62affac5f95194873bace986095eb2517cf922d4 100644 (file)
@@ -739,7 +739,7 @@ func printpanics(p *_panic) {
        }
        print("panic: ")
        printpanicval(p.arg)
-       if p.repanicked {
+       if p.recovered && p.repanicked {
                print(" [recovered, repanicked]")
        } else if p.recovered {
                print(" [recovered]")
index 556215a71ea08fbe45fb2762a0c377a2cad55004..fcce388871158d8f343857670ae85a3d133968fa 100644 (file)
@@ -22,6 +22,7 @@ func init() {
        register("RepanickedPanic", RepanickedPanic)
        register("RepanickedMiddlePanic", RepanickedMiddlePanic)
        register("RepanickedPanicSandwich", RepanickedPanicSandwich)
+       register("DoublePanicWithSameValue", DoublePanicWithSameValue)
 }
 
 func test(name string) {
@@ -189,3 +190,13 @@ func RepanickedPanicSandwich() {
                panic("outer")
        }()
 }
+
+// Double panic with same value and not recovered.
+// See issue 76099.
+func DoublePanicWithSameValue() {
+       var e any = "message"
+       defer func() {
+               panic(e)
+       }()
+       panic(e)
+}