From 354091087955f6fcb7216ee03a2397376e4526c4 Mon Sep 17 00:00:00 2001 From: Remember <36129334+wuqinqiang@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:43:42 +0800 Subject: [PATCH] fix(backoff): close of closed out channel (#3871) * fix: close of closed channel * feat: replace Try0 to std --- pkg/util/wait/backoff.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/util/wait/backoff.go b/pkg/util/wait/backoff.go index 45e0ab68..048c9591 100644 --- a/pkg/util/wait/backoff.go +++ b/pkg/util/wait/backoff.go @@ -16,10 +16,9 @@ package wait import ( "math/rand" + "sync" "time" - "github.com/samber/lo" - "github.com/fatedier/frp/pkg/util/util" ) @@ -182,16 +181,18 @@ 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() { + go func() { select { case <-ch: - close(out) + closeOnce.Do(func() { + close(out) + }) case <-out: } - }) + }() } return out }