Skip to content

Commit

Permalink
optimization:enhance robustness
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxiaomin committed Nov 5, 2020
1 parent 3cf5870 commit d02efac
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sync/task_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import (
"fmt"
"log"
"math/rand"
"os"
"runtime/debug"
"sync"
"sync/atomic"
"time"
)

import (
Expand Down Expand Up @@ -171,7 +174,15 @@ func (p *TaskPool) run(id int, q chan task) error {

case t, ok = <-q:
if ok {
t()
func() {
defer func() {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "%s goroutine panic: %v\n%s\n",
time.Now(), r, string(debug.Stack()))
}
}()
t()
}()
}
}
}
Expand Down

0 comments on commit d02efac

Please sign in to comment.