From 8adf35d48059647c6f93e47d2431b8c7884a6735 Mon Sep 17 00:00:00 2001 From: wuqinqiang <1185079673@qq.com> Date: Thu, 21 Dec 2023 10:53:27 +0800 Subject: [PATCH] fix: close of closed channel --- pkg/util/wait/backoff.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/util/wait/backoff.go b/pkg/util/wait/backoff.go index 45e0ab68..bb3e50d6 100644 --- a/pkg/util/wait/backoff.go +++ b/pkg/util/wait/backoff.go @@ -16,6 +16,7 @@ package wait import ( "math/rand" + "sync" "time" "github.com/samber/lo" @@ -182,13 +183,15 @@ func Until(f func(), period time.Duration, stopCh <-chan struct{}) { func MergeAndCloseOnAnyStopChannel[T any](upstreams ...<-chan T) <-chan T { out := make(chan T) - + closeOnce := sync.Once{} for _, upstream := range upstreams { ch := upstream go lo.Try0(func() { select { case <-ch: - close(out) + closeOnce.Do(func() { + close(out) + }) case <-out: } })