Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix concurrency issue in SumComputeTime #2029

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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