diff --git a/worker.go b/worker.go index 856b46f..84a65c4 100644 --- a/worker.go +++ b/worker.go @@ -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. diff --git a/worker_func.go b/worker_func.go index 2d93589..3ab6c1f 100644 --- a/worker_func.go +++ b/worker_func.go @@ -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.