From d6cd5a7e726c9bb8578e7aabdbf3488dc8d080b6 Mon Sep 17 00:00:00 2001 From: Cholerae Hu Date: Wed, 11 Sep 2019 16:39:55 +0800 Subject: [PATCH] worker: decRunning when revertWorker is false Signed-off-by: Cholerae Hu --- worker.go | 8 +++----- worker_func.go | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/worker.go b/worker.go index b79d9b8..f38e9d2 100644 --- a/worker.go +++ b/worker.go @@ -48,9 +48,8 @@ func (w *goWorker) run() { w.pool.incRunning() go func() { defer func() { + w.pool.decRunning() if p := recover(); p != nil { - w.pool.decRunning() - w.pool.workerCache.Put(w) if w.pool.panicHandler != nil { w.pool.panicHandler(p) } else { @@ -60,17 +59,16 @@ func (w *goWorker) run() { log.Printf("worker exits from panic: %s\n", string(buf[:n])) } } + w.pool.workerCache.Put(w) }() for f := range w.task { if f == nil { - w.pool.decRunning() - w.pool.workerCache.Put(w) return } f() if ok := w.pool.revertWorker(w); !ok { - break + return } } }() diff --git a/worker_func.go b/worker_func.go index befd966..4c56ae8 100644 --- a/worker_func.go +++ b/worker_func.go @@ -48,9 +48,8 @@ func (w *goWorkerWithFunc) run() { w.pool.incRunning() go func() { defer func() { + w.pool.decRunning() if p := recover(); p != nil { - w.pool.decRunning() - w.pool.workerCache.Put(w) if w.pool.panicHandler != nil { w.pool.panicHandler(p) } else { @@ -60,17 +59,16 @@ func (w *goWorkerWithFunc) run() { log.Printf("worker with func exits from panic: %s\n", string(buf[:n])) } } + w.pool.workerCache.Put(w) }() for args := range w.args { if args == nil { - w.pool.decRunning() - w.pool.workerCache.Put(w) return } w.pool.poolFunc(args) if ok := w.pool.revertWorker(w); !ok { - break + return } } }()