Q:

Generate panic stacktrace on working process

Situation:
I have a race condition problem in my Go server program:
go func() {
    i := 1
    for {
        fmt.Printf("I am alive: %d\n",i)
        time.Sleep(1 * time.Second)
        i+=1
    }
}()

After lots of parallel requests to my program, it completely hangs up, and even the goroutine in main does not write anything more.
Question:
I want to eliminate this problem. For that, I want to produce a panic in this state and receive a stack dump of all goroutines.
Is there any way to do this?

A:

If you want to get a stack  trace from a Go process, the default signal handler for SIGQUIT will print a stack trace and exit.
There are also some useful settings that can be enabled through the GODEBUG and GOTRACEBACK environment variables, documented in the runtime package. In this case using schedtrace, scheddetail, or gctrace may help show what is happening when your program freezes. 

