Closed anpenggang closed 2 years ago
Hey @anpenggang!
What happens to the pool when a worker panic?
When a task panics, the worker goroutine that was executing it calls the configured PanicHandler
function passing the captured panic object and then continues processing other tasks. The default panic handler simply logs the panic and its stack trace, so you should see something like this:
Worker exits from a panic: 11111
Stack trace: goroutine 7 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:24 +0x65
github.com/alitto/pond.defaultPanicHandler({0x4988c0, 0x4c84f8})
...
You can also override the default panic handler to perform some custom handling. E.g.:
myPanicHandler := func(p interface{}) {
fmt.Printf("Task panicked: %v", p)
}
pool := pond.New(10, 1000, pond.PanicHandler(myPanicHandler)))
I see you posted some error logs after your question, but I couldn't reproduce it using the example you provided. This is the code I executed:
package main
import (
"fmt"
"runtime"
"github.com/alitto/pond"
)
func main() {
pool := pond.New(10, 50)
defer pool.StopAndWait()
group := pool.Group()
group.Submit(func() {
fmt.Println("NumGoroutine:", runtime.NumGoroutine())
panic(11111)
})
group.Wait()
}
Could you provide more context about those errors?
Thanks,it‘s not pond's problem. i have a global map to write by group, but map is not safety,so the process panic
` pool := pond.New(10, 50) defer pool.StopAndWait()
` Hi: What happens to the pool when a worker panic?
goroutine 331 [chan receive]: github.com/alitto/pond.worker(0xc00e683548, 0xc00e6ceae0, 0xc00e6bf23c, 0xc00e6c3400, 0xc00e6c3410) /home/work/go/pkg/mod/github.com/alitto/pond@v1.5.0/pond.go:430 +0xbf created by github.com/alitto/pond.(*WorkerPool).maybeStartWorker /home/work/go/pkg/mod/github.com/alitto/pond@v1.5.0/pond.go:348 +0xe9
goroutine 329 [running]: goroutine running on other thread; stack unavailable created by github.com/alitto/pond.(*WorkerPool).maybeStartWorker /home/work/go/pkg/mod/github.com/alitto/pond@v1.5.0/pond.go:348 +0xe9