Take write lock for rate limit map

This commit is contained in:
Neil Alexander 2020-10-16 13:26:04 +01:00
parent 4a7fb9c045
commit d52362a106
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -73,8 +73,13 @@ func (l *rateLimits) rateLimit(req *http.Request) *util.JSONResponse {
// let's create one.
rateLimit, ok := l.limits[caller]
if !ok {
l.limits[caller] = make(chan struct{}, l.requestThreshold)
rateLimit = l.limits[caller]
rateLimit = make(chan struct{}, l.requestThreshold)
l.limitsMutex.RUnlock()
l.limitsMutex.Lock()
l.limits[caller] = rateLimit
l.limitsMutex.Unlock()
l.limitsMutex.RLock()
}
// Check if the user has got free resource slots for this request.