From d75b800473142ca1bb4d21a9d003bbe66a5bc5bf Mon Sep 17 00:00:00 2001 From: Termina1 Date: Fri, 6 Sep 2024 17:02:23 +0300 Subject: [PATCH] fix queue potential leak --- utils/queue.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/utils/queue.go b/utils/queue.go index 19773d3..73de1ba 100644 --- a/utils/queue.go +++ b/utils/queue.go @@ -62,12 +62,14 @@ func (q *FDQueue[S, E]) Feed() (recs S, err error) { return case <-time.After(q.timeout): return - case pkg := <-q.ch: + case pkg, ok := <-q.ch: + if !ok { + return + } recs = append(recs, pkg) - for ok := false; ok; { - pkg, ok = <-q.ch - recs = append(recs, pkg) + if len(q.ch) == 0 { + return } - return } + return }