update limiter

This commit is contained in:
ginuerzh
2022-09-14 20:00:35 +08:00
parent 91c12882f5
commit 01d7dc77c6
34 changed files with 1171 additions and 79 deletions

View File

@ -102,7 +102,7 @@ type connLimiter struct {
ipLimits map[string]ConnLimitGenerator
cidrLimits cidranger.Ranger
limits map[string]limiter.Limiter
mu sync.RWMutex
mu sync.Mutex
cancelFunc context.CancelFunc
options options
}

View File

@ -20,7 +20,7 @@ func (l *llimiter) Limit() int {
}
func (l *llimiter) Allow(n int) bool {
if atomic.AddInt64(&l.current, int64(n)) >= int64(l.limit) {
if atomic.AddInt64(&l.current, int64(n)) > int64(l.limit) {
if n > 0 {
atomic.AddInt64(&l.current, -int64(n))
}