Skip to content

Commit

Permalink
✨ feat: recover worker panics
Browse files Browse the repository at this point in the history
  • Loading branch information
0xE8551CCB committed Oct 12, 2019
1 parent adf3ca3 commit ba49fe0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,18 @@ func processRequest(request interface{}) {
select {
case <-req.ctx.Done():
case req.resultChan <- func() *jobResult {
var result jobResult
defer func() {
if p := recover(); p != nil {
result.Err = errors.Errorf("crashed, failed to process request: %s", p)
}
}()

data, err := req.pf(req.payload)
return &jobResult{Data: data, Err: err}
result.Data = data
result.Err = err

return &result
}():
}
default:
Expand Down

0 comments on commit ba49fe0

Please sign in to comment.