This is an automated email from the ASF dual-hosted git repository. tianxiaoliang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push: new 9d50638 Fix: Gopool should reuse worker with certainty (#963) 9d50638 is described below commit 9d50638496e37fa3e5bfac388e382f932430b10c Author: szt-sketch <76426857+szt-ske...@users.noreply.github.com> AuthorDate: Fri May 7 10:47:47 2021 +0800 Fix: Gopool should reuse worker with certainty (#963) --- pkg/gopool/goroutines.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/gopool/goroutines.go b/pkg/gopool/goroutines.go index d5ca917..cf1a53b 100644 --- a/pkg/gopool/goroutines.go +++ b/pkg/gopool/goroutines.go @@ -81,10 +81,14 @@ func (g *Pool) execute(f func(ctx context.Context)) { func (g *Pool) Do(f func(context.Context)) *Pool { defer log.Recover() select { - case g.pending <- f: // block if workers are busy - case g.workers <- struct{}{}: - g.wg.Add(1) - go g.loop(f) + case g.pending <- f: // try to reuse worker first + default: + select { + case g.pending <- f: // block if workers are busy + case g.workers <- struct{}{}: + g.wg.Add(1) + go g.loop(f) + } } return g }