Skip to content

Commit

Permalink
The mutex should be unlocked before the recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Jan 8, 2022
1 parent 145152c commit c5e0343
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ func (r *WindowRateLimiter) GetJoinLimit() int {
}

func (r *WindowRateLimiter) Throttle(count int) {
r.mutex.Lock()
defer r.mutex.Unlock()

if r.joinLimit == Unlimited {
return
}

r.mutex.Lock()
newWindow := []time.Time{}

for i := 0; i < len(r.window); i++ {
Expand All @@ -67,10 +64,12 @@ func (r *WindowRateLimiter) Throttle(count int) {
newWindow = append(newWindow, time.Now())
}
r.window = newWindow
r.mutex.Unlock()
return
}

time.Sleep(time.Until(r.window[0].Add(TwitchRateLimitWindow).Add(time.Millisecond * 100)))
r.mutex.Unlock()
r.Throttle(count)
}

Expand Down

0 comments on commit c5e0343

Please sign in to comment.