From 5fd2e64fc1db2060542eb0e102b3bc8e9463d00e Mon Sep 17 00:00:00 2001 From: Cabinfever_B Date: Wed, 8 Nov 2023 17:48:15 +0800 Subject: [PATCH] fix race Signed-off-by: Cabinfever_B --- pkg/ratelimit/limiter.go | 5 ++--- pkg/ratelimit/limiter_test.go | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/ratelimit/limiter.go b/pkg/ratelimit/limiter.go index 391f7014525..d0596df8bf8 100644 --- a/pkg/ratelimit/limiter.go +++ b/pkg/ratelimit/limiter.go @@ -173,10 +173,9 @@ func (l *limiter) updateConcurrencyConfig(limit uint64) UpdateStatus { return ConcurrencyChanged } return ConcurrencyNoChange - } else { - l.concurrency.setLimit(limit) - return ConcurrencyChanged } + l.concurrency.setLimit(limit) + return ConcurrencyChanged } l.concurrency = newConcurrencyLimiter(limit) return ConcurrencyChanged diff --git a/pkg/ratelimit/limiter_test.go b/pkg/ratelimit/limiter_test.go index 9a3bd02cf0a..432c10dfda6 100644 --- a/pkg/ratelimit/limiter_test.go +++ b/pkg/ratelimit/limiter_test.go @@ -27,10 +27,13 @@ import ( ) type releaseUtil struct { + mu sync.Mutex dones []DoneFunc } func (r *releaseUtil) release() { + r.mu.Lock() + defer r.mu.Unlock() if len(r.dones) > 0 { r.dones[0]() r.dones = r.dones[1:] @@ -38,6 +41,8 @@ func (r *releaseUtil) release() { } func (r *releaseUtil) append(d DoneFunc) { + r.mu.Lock() + defer r.mu.Unlock() r.dones = append(r.dones, d) }