summaryrefslogtreecommitdiff
path: root/test/fixedbugs
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-06-06 16:52:14 -0400
committerRuss Cox <rsc@golang.org>2014-06-06 16:52:14 -0400
commitcffbc21f50df09d5a33ab78254f8eb64cdff92bc (patch)
treeddcb091a9c4314ebc1e104e00e162f61c231df37 /test/fixedbugs
parent6bf435da39375c4d5e030649a0ca0f35440392fe (diff)
downloadgo-cffbc21f50df09d5a33ab78254f8eb64cdff92bc.tar.gz
runtime: fix panic stack during runtime.Goexit during panic
A runtime.Goexit during a panic-invoked deferred call left the panic stack intact even though all the stack frames are gone when the goroutine is torn down. The next goroutine to reuse that struct will have a bogus panic stack and can cause the traceback routines to walk into garbage. Most likely to happen during tests, because t.Fatal might be called during a deferred func and uses runtime.Goexit. This "not enough cleared in Goexit" failure mode has happened to us multiple times now. Clear all the pointers that don't make sense to keep, not just gp->panic. Fixes issue 8158. LGTM=iant, dvyukov R=iant, dvyukov CC=golang-codereviews https://codereview.appspot.com/102220043
Diffstat (limited to 'test/fixedbugs')
-rw-r--r--test/fixedbugs/issue8158.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/fixedbugs/issue8158.go b/test/fixedbugs/issue8158.go
new file mode 100644
index 000000000..b110de11f
--- /dev/null
+++ b/test/fixedbugs/issue8158.go
@@ -0,0 +1,41 @@
+// run
+
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "runtime"
+ "time"
+)
+
+func main() {
+ c := make(chan bool, 1)
+ go f1(c)
+ <-c
+ time.Sleep(10 * time.Millisecond)
+ go f2(c)
+ <-c
+}
+
+func f1(done chan bool) {
+ defer func() {
+ recover()
+ done <- true
+ runtime.Goexit() // left stack-allocated Panic struct on gp->panic stack
+ }()
+ panic("p")
+}
+
+func f2(done chan bool) {
+ defer func() {
+ recover()
+ done <- true
+ runtime.Goexit()
+ }()
+ time.Sleep(10 * time.Millisecond) // overwrote Panic struct with Timer struct
+ runtime.GC() // walked gp->panic list, found mangled Panic struct, crashed
+ panic("p")
+}