From 313f136d004dc2497fcc58b0d844fb7d068565b7 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Tue, 18 Jun 2024 12:09:09 +0800 Subject: [PATCH] bug: fix the last error being missed in ReleaseTimeout() for multi-pool (#334) --- multipool.go | 13 +++---------- multipool_func.go | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/multipool.go b/multipool.go index ad5db10..3f78ce2 100644 --- a/multipool.go +++ b/multipool.go @@ -201,16 +201,9 @@ func (mp *MultiPool) ReleaseTimeout(timeout time.Duration) error { _ = wg.Wait() - var ( - i int - errStr strings.Builder - ) - for err := range errCh { - i++ - if i == len(mp.pools) { - break - } - if err != nil { + var errStr strings.Builder + for i := 0; i < len(mp.pools); i++ { + if err := <-errCh; err != nil { errStr.WriteString(err.Error()) errStr.WriteString(" | ") } diff --git a/multipool_func.go b/multipool_func.go index 257b16e..868c0de 100644 --- a/multipool_func.go +++ b/multipool_func.go @@ -191,16 +191,9 @@ func (mp *MultiPoolWithFunc) ReleaseTimeout(timeout time.Duration) error { _ = wg.Wait() - var ( - i int - errStr strings.Builder - ) - for err := range errCh { - i++ - if i == len(mp.pools) { - break - } - if err != nil { + var errStr strings.Builder + for i := 0; i < len(mp.pools); i++ { + if err := <-errCh; err != nil { errStr.WriteString(err.Error()) errStr.WriteString(" | ") }