Skip to content

Commit

Permalink
fix concurrency issue in SumComputeTime (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj authored Aug 19, 2024
1 parent f9c3978 commit 6d47054
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/walletextension/ratelimiter/rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (rl *RateLimiter) SumComputeTime(userID common.Address) time.Duration {

var totalComputeTime time.Duration
if user, exists := rl.users[userID]; exists {
user.mu.RLock() // lock the user to prevent changes while reading
defer user.mu.RUnlock()

cutoff := time.Now().Add(-rl.window)
for _, interval := range user.CurrentRequests {
// if the request has ended and it's within the window, add the compute time
Expand Down

0 comments on commit 6d47054

Please sign in to comment.