mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: crash when func main calls Goexit and all other goroutines exit
This has typically crashed in the past, although usually with an 'all goroutines are asleep - deadlock!' message that shows no goroutines (because there aren't any). Previous discussion at: https://groups.google.com/d/msg/golang-nuts/uCT_7WxxopQ/BoSBlLFzUTkJ https://groups.google.com/d/msg/golang-dev/KUojayEr20I/u4fp_Ej5PdUJ http://golang.org/issue/7711 There is general agreement that runtime.Goexit terminates the main goroutine, so that main cannot return, so the program does not exit. The interpretation that all other goroutines exiting causes an exit(0) is relatively new and was not part of those discussions. That is what this CL changes. Thankfully, even though the exit(0) has been there for a while, some other accounting bugs made it very difficult to trigger, so it is reasonable to replace. In particular, see golang.org/issue/7711#c10 for an examination of the behavior across past releases. Fixes #7711. LGTM=iant, r R=golang-codereviews, iant, dvyukov, r CC=golang-codereviews https://golang.org/cl/88210044
This commit is contained in:
parent
468cf82780
commit
ade6bc68b0
4 changed files with 22 additions and 8 deletions
|
|
@ -111,8 +111,9 @@ func TestLockedDeadlock2(t *testing.T) {
|
|||
|
||||
func TestGoexitDeadlock(t *testing.T) {
|
||||
output := executeTest(t, goexitDeadlockSource, nil)
|
||||
if output != "" {
|
||||
t.Fatalf("expected no output, got:\n%s", output)
|
||||
want := "no goroutines (main called runtime.Goexit) - deadlock!"
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("output:\n%s\n\nwant output containing: %s", output, want)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -144,13 +145,12 @@ panic: again
|
|||
|
||||
}
|
||||
|
||||
func TestGoexitExit(t *testing.T) {
|
||||
func TestGoexitCrash(t *testing.T) {
|
||||
output := executeTest(t, goexitExitSource, nil)
|
||||
want := ""
|
||||
if output != want {
|
||||
t.Fatalf("output:\n%s\n\nwanted:\n%s", output, want)
|
||||
want := "no goroutines (main called runtime.Goexit) - deadlock!"
|
||||
if !strings.Contains(output, want) {
|
||||
t.Fatalf("output:\n%s\n\nwant output containing: %s", output, want)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const crashSource = `
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue