]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make return from main wait for active panic
authorRuss Cox <rsc@golang.org>
Fri, 15 Feb 2013 19:48:35 +0000 (14:48 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 15 Feb 2013 19:48:35 +0000 (14:48 -0500)
Arguably if this happens the program is buggy anyway,
but letting the panic continue looks better than interrupting it.
Otherwise things like this are possible, and confusing:

$ go run x.go
panic: $ echo $?
0
$

Fixes #3934.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7322083

src/pkg/runtime/proc.c

index 8a6fa378f2d1caa1c0574bcdf98fba040fe02a56..5c60cddf9babb0fbe1e54e3f16b0766f5c842c97 100644 (file)
@@ -253,6 +253,14 @@ runtime·main(void)
        main·main();
        if(raceenabled)
                runtime·racefini();
+       
+       // Make racy client program work: if panicking on
+       // another goroutine at the same time as main returns,
+       // let the other goroutine finish printing the panic trace.
+       // Once it does, it will exit. See issue 3934.
+       if(runtime·panicking)
+               runtime·park(nil, nil, "panicwait");
+
        runtime·exit(0);
        for(;;)
                *(int32*)runtime·main = 0;