mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: delay exiting while panic is running deferred functions
Try to avoid a race between the main goroutine exiting and a panic occurring. Don't try too hard, to avoid hanging. Updates #3934 Fixes #20018 Change-Id: I57a02b6d795d2a61f1cadd137ce097145280ece7 Reviewed-on: https://go-review.googlesource.com/41052 Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
3c745d750e
commit
2d86f49428
5 changed files with 87 additions and 4 deletions
|
|
@ -568,3 +568,32 @@ func TestPanicInlined(t *testing.T) {
|
|||
pt := new(point)
|
||||
pt.negate()
|
||||
}
|
||||
|
||||
// Test for issues #3934 and #20018.
|
||||
// We want to delay exiting until a panic print is complete.
|
||||
func TestPanicRace(t *testing.T) {
|
||||
testenv.MustHaveGoRun(t)
|
||||
|
||||
exe, err := buildTestProg(t, "testprog")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := testEnv(exec.Command(exe, "PanicRace")).CombinedOutput()
|
||||
if err == nil {
|
||||
t.Error("program exited successfully, should have failed")
|
||||
}
|
||||
|
||||
t.Logf("%s\n", got)
|
||||
|
||||
wants := []string{
|
||||
"panic: crash",
|
||||
"PanicRace",
|
||||
"created by ",
|
||||
}
|
||||
for _, want := range wants {
|
||||
if !bytes.Contains(got, []byte(want)) {
|
||||
t.Errorf("did not find expected string %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue