-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: wait for active panic before exit on Windows #20018
Comments
I can't reproduce it on |
@mvdan Yes, it's ok on Linux. I only test it on Windows and linux, and linux is ok. |
No idea why this fails on Windows. The fix for #3934 (https://golang.org/cl/7322083) was not OS-specific. Somebody with a Windows system will have to debug what is happening. |
/cc @alexbrainman |
the runtime.main function not enter gopark branch at all if there is no panic information output. |
if panicking != 0 {
println("main.main park")
gopark(nil, nil, "panicwait", traceEvGoStop, 1)
}
print("main.main exit with panicking : ", panicking, "\n") i modify runtime.main like this, and when no panic information, |
Thanks for looking into it. I think I see the problem, but I don't understand why it only appears on Windows. The problem is that calling I can't quite decide how important it is to fix this problem. |
yes, i doubt it also for that only appears on Windows, today i check it on linux again and it's ok. --- a/src/runtime/panic.go
+++ b/src/runtime/panic.go
@@ -412,6 +412,9 @@ func printpanics(p *_panic) {
// The implementation of the predeclared function panic.
func gopanic(e interface{}) {
+ lock(&userpaniclk)
+ atomic.Xadd(&userpanicing, 1)
+ unlock(&userpaniclk)
gp := getg()
if gp.m.curg != gp {
print("panic: ")
@@ -516,6 +519,9 @@ func gopanic(e interface{}) {
// Pass information about recovering frame to recovery.
gp.sigcode0 = uintptr(sp)
gp.sigcode1 = pc
+ lock(&userpaniclk)
+ atomic.Xadd(&userpanicing, -1)
+ unlock(&userpaniclk)
mcall(recovery)
throw("recovery failed") // mcall should not return
}
@@ -526,7 +532,13 @@ func gopanic(e interface{}) {
// the world, we call preprintpanics to invoke all necessary Error
// and String methods to prepare the panic strings before startpanic.
preprintpanics(gp._panic)
+ println("gopanic: start panic")
startpanic()
+
+ lock(&userpaniclk)
+ atomic.Xadd(&userpanicing, -1)
+ unlock(&userpaniclk)
+ --- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -191,10 +191,22 @@ func main() {
// 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.
+ lock(&userpaniclk)
+ println("check userpanicing")
+ if userpanicing != 0 {
+ unlock(&userpaniclk)
+ gopark(nil, nil, "panicwait", traceEvGoStop, 1)
+ } else {
+ unlock(&userpaniclk)
+ }
+ println("main.main is exit now, check paniking start, ", panicking)
if panicking != 0 {
+ println("main.main park")
gopark(nil, nil, "panicwait", traceEvGoStop, 1)
}
+ print("main.main exit with panicking : ", panicking, "\n")
+ --- a/src/runtime/runtime2.go
+++ b/src/runtime/runtime2.go
@@ -750,6 +750,9 @@ var (
goarm uint8 // set by cmd/link on arm systems
framepointer_enabled bool // set by cmd/link
+
+ userpaniclk mutex
+ userpanicing uint32 I don't know dose it ok on recover. |
and we check dose main.main is exit when recover, if it is, change runtime.mian to run again. |
I tried to debug this a little. I see 2 threads racing to exit process:
@ianlancetaylor if you have some things for me to try, let me know. Alex |
@alexbrainman Can you see if https://golang.org/cl/41052 fixes the problem on Windows? I was able to recreate the problem on GNU/Linux by adding a This might be too much mechanism for a racy program. We'll see what other people think. |
Yes, that fixes this issue here. Thank you.
I feel the same. Let Austin decide if it is worth it. Alex |
@alexbrainman @ianlancetaylor but i think this will hard to appear. |
@sydnash Yes. The program is racy. |
CL https://golang.org/cl/41052 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8
What operating system and processor architecture are you using (
go env
)?windows/amd64
$ go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\gowork
set GORACE=
set GOROOT=D:\Go
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
What did you do?
p.go
What did you expect to see?
I want to see the output information as blow ever time i run it.
panic: boom
goroutine 17 [running]:
main.run(0xc042040000)
D:/gowork/src/github.com/sydnash/practice/select/p.go:9 +0x95
created by main.main
D:/gowork/src/github.com/sydnash/practice/select/p.go:15 +0x72
exit status 2
What did you see instead?
I found it some times exit with status 0 and without panic information output.
The text was updated successfully, but these errors were encountered: