From: Michael Anthony Knyszek Date: Wed, 30 Jul 2025 00:36:40 +0000 (+0000) Subject: runtime: prioritize panic output over racefini X-Git-Tag: go1.26rc1~411 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=89dee70484669d546fff6ca29a4717368af351ff;p=gostls13.git runtime: prioritize panic output over racefini For some reason CL 646198 uncovered #3934 and #20018 again, but only in race mode. It turns out that because racefini does not return, and racefini is called early after main returns, we would not properly wait for a concurrent panic to complete. This would result in fairly consistent failures of TestPanicRace, which specifically looks for the panic output to appear if main concurrently exits. The important part of this change is that race mode will no longer have the bug described in #3934 and #20018. A byproduct, however, is that racefini is that we're essentially prioritizing the panic output over racefini in this scenario. If racefini were to reveal a latent race condition and fail, we'll prefer to surface the panic. Such a case is probably fine, because the panic is always an crashing, unrecoverable panic. For #3934. For #20018. Change-Id: I0674a75c918563c5ec4ee1eec057dfd096fcfbc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/691795 LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Knyszek Reviewed-by: Michael Pratt --- diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 7d02363cc9..2b8ca549ad 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -788,9 +788,6 @@ func TestPanicInlined(t *testing.T) { // Test for issues #3934 and #20018. // We want to delay exiting until a panic print is complete. func TestPanicRace(t *testing.T) { - if race.Enabled { - t.Skip("racefini exits program before main can delay exiting") - } testenv.MustHaveGoRun(t) exe, err := buildTestProg(t, "testprog") diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 89080b48de..ef3a0b7a0e 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -288,13 +288,6 @@ func main() { fn := main_main // make an indirect call, as the linker doesn't know the address of the main package when laying down the runtime fn() - exitHooksRun := false - if raceenabled { - runExitHooks(0) // run hooks now, since racefini does not return - exitHooksRun = true - racefini() - } - // Check for C memory leaks if using ASAN and we've made cgo calls, // or if we are running as a library in a C program. // We always make one cgo call, above, to notify_runtime_init_done, @@ -302,6 +295,7 @@ func main() { // No point in leak checking if no cgo calls, since leak checking // just looks for objects allocated using malloc and friends. // Just checking iscgo doesn't help because asan implies iscgo. + exitHooksRun := false if asanenabled && (isarchive || islibrary || NumCgoCall() > 1) { runExitHooks(0) // lsandoleakcheck may not return exitHooksRun = true @@ -327,6 +321,9 @@ func main() { if !exitHooksRun { runExitHooks(0) } + if raceenabled { + racefini() // does not return + } exit(0) for {