From 2399c4ff5c0cd00c52c41bb27798022f75b4d75b Mon Sep 17 00:00:00 2001 From: M09Ic Date: Thu, 17 Nov 2022 16:58:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E9=80=BB=E8=BE=91,=20=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E6=97=A0=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=BE=93?= =?UTF-8?q?=E5=87=BA,=20=E6=88=96=E7=AE=A1=E9=81=93=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pool.go | 8 +++----- internal/runner.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/pool.go b/internal/pool.go index d403f97..e70cea2 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -52,7 +52,6 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { return pool.buildPathRequest(s) } pool.check = func() { - pool.wg.Add(1) _ = pool.pool.Invoke(newUnit(pkg.RandPath(), CheckSource)) if pool.failedCount > pool.BreakThreshold { @@ -67,7 +66,6 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { } pool.check = func() { - pool.wg.Add(1) _ = pool.pool.Invoke(newUnit(pkg.RandHost(), CheckSource)) if pool.failedCount > pool.BreakThreshold { @@ -83,7 +81,6 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { req, err := pool.genReq(unit.path) if err != nil { logs.Log.Error(err.Error()) - return } var bl *pkg.Baseline @@ -148,7 +145,6 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { pool.bar.Done() } - pool.wg.Done() }) pool.pool = p @@ -160,6 +156,7 @@ func NewPool(ctx context.Context, config *pkg.Config) (*Pool, error) { } } else { pool.BaseCompare(bl) + pool.wg.Done() } } @@ -260,6 +257,7 @@ Loop: break Loop } } + //p.wg.Add(100) p.wg.Wait() p.Close() } @@ -363,7 +361,7 @@ func (p *Pool) recover() { } func (p *Pool) Close() { - for !p.analyzeDone { + for p.analyzeDone { time.Sleep(time.Duration(100) * time.Millisecond) } close(p.tempCh) diff --git a/internal/runner.go b/internal/runner.go index 7ed61bb..eba69f0 100644 --- a/internal/runner.go +++ b/internal/runner.go @@ -159,7 +159,11 @@ func (r *Runner) Outputting() { for { select { - case bl := <-r.OutputCh: + case bl, ok := <-r.OutputCh: + if !ok { + return + } + if bl.IsValid { outFunc(bl) } else { @@ -172,7 +176,10 @@ func (r *Runner) Outputting() { go func() { for { select { - case bl := <-r.FuzzyCh: + case bl, ok := <-r.FuzzyCh: + if !ok { + return + } if r.Fuzzy { logs.Log.Console("[baseline.fuzzy] " + bl.String() + "\n") }