From 2dde03fd560ec05917bcee0c373c935613141f6b Mon Sep 17 00:00:00 2001 From: iBug Date: Mon, 13 Apr 2026 15:34:10 +0800 Subject: [PATCH] Protect queue.GetMax() with lock --- pkg/queue/queue.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/queue/queue.go b/pkg/queue/queue.go index ff4dc8a..7488239 100644 --- a/pkg/queue/queue.go +++ b/pkg/queue/queue.go @@ -31,8 +31,10 @@ func New(max, maxQueued int) *Queue { } func (q *Queue) GetMax() int { - // This is not protected by q.mu, but we don't expect racing calls between GetMax and SetMax. - return q.max + q.mu.Lock() + ret := q.max + q.mu.Unlock() + return ret } func (q *Queue) SetMax(max, maxQueued int) {