opt: use runtime/debug.Stack() to print stack trace of panic

This commit is contained in:
Andy Pan 2023-03-23 14:42:17 +08:00
parent 3110e41921
commit 7a56a5c082
2 changed files with 4 additions and 10 deletions

View File

@ -23,7 +23,7 @@
package ants
import (
"runtime"
"runtime/debug"
"time"
)
@ -53,10 +53,7 @@ func (w *goWorker) run() {
if ph := w.pool.options.PanicHandler; ph != nil {
ph(p)
} else {
w.pool.options.Logger.Printf("worker exits from a panic: %v\n", p)
var buf [4096]byte
n := runtime.Stack(buf[:], false)
w.pool.options.Logger.Printf("worker exits from panic: %s\n", string(buf[:n]))
w.pool.options.Logger.Printf("worker exits from panic: %v\n%s\n", p, debug.Stack())
}
}
// Call Signal() here in case there are goroutines waiting for available workers.

View File

@ -23,7 +23,7 @@
package ants
import (
"runtime"
"runtime/debug"
"time"
)
@ -53,10 +53,7 @@ func (w *goWorkerWithFunc) run() {
if ph := w.pool.options.PanicHandler; ph != nil {
ph(p)
} else {
w.pool.options.Logger.Printf("worker with func exits from a panic: %v\n", p)
var buf [4096]byte
n := runtime.Stack(buf[:], false)
w.pool.options.Logger.Printf("worker with func exits from panic: %s\n", string(buf[:n]))
w.pool.options.Logger.Printf("worker exits from panic: %v\n%s\n", p, debug.Stack())
}
}
// Call Signal() here in case there are goroutines waiting for available workers.