mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-25 07:43:10 -06:00
Take write lock for rate limit map
This commit is contained in:
parent
4a7fb9c045
commit
d52362a106
|
|
@ -73,8 +73,13 @@ func (l *rateLimits) rateLimit(req *http.Request) *util.JSONResponse {
|
||||||
// let's create one.
|
// let's create one.
|
||||||
rateLimit, ok := l.limits[caller]
|
rateLimit, ok := l.limits[caller]
|
||||||
if !ok {
|
if !ok {
|
||||||
l.limits[caller] = make(chan struct{}, l.requestThreshold)
|
rateLimit = make(chan struct{}, l.requestThreshold)
|
||||||
rateLimit = l.limits[caller]
|
|
||||||
|
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.
|
// Check if the user has got free resource slots for this request.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue