runtime: do not print recovered when double panic with the same value

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>
This commit is contained in:
Youlin Feng 2025-10-29 13:11:48 +08:00 committed by Gopher Robot
parent 9859b43643
commit c93766007d
3 changed files with 21 additions and 1 deletions

View 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)

View 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]")

View 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)
}