Skip to content

Commit

Permalink
fix race
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <[email protected]>
  • Loading branch information
CabinfeverB committed Nov 8, 2023
1 parent bab5c8a commit 5fd2e64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/ratelimit/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/ratelimit/limiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ 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:]
}
}

func (r *releaseUtil) append(d DoneFunc) {
r.mu.Lock()
defer r.mu.Unlock()
r.dones = append(r.dones, d)
}

Expand Down

0 comments on commit 5fd2e64

Please sign in to comment.