From e6e026f42016712119d66591b1b43574447aadc2 Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Tue, 12 Nov 2019 11:06:05 +0100 Subject: [PATCH] Fix rate limiting and SSE --- pkg/middlewares/ratelimiter/rate_limiter.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/middlewares/ratelimiter/rate_limiter.go b/pkg/middlewares/ratelimiter/rate_limiter.go index 4e51ec3c9..2940c22ae 100644 --- a/pkg/middlewares/ratelimiter/rate_limiter.go +++ b/pkg/middlewares/ratelimiter/rate_limiter.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "net/http" - "sync" "time" "github.com/containous/traefik/v2/pkg/config/dynamic" @@ -35,8 +34,7 @@ type rateLimiter struct { sourceMatcher utils.SourceExtractor next http.Handler - bucketsMu sync.Mutex - buckets *ttlmap.TtlMap // actual buckets, keyed by source. + buckets *ttlmap.TtlMap // actual buckets, keyed by source. } // New returns a rate limiter middleware. @@ -57,7 +55,7 @@ func New(ctx context.Context, next http.Handler, config dynamic.RateLimit, name return nil, err } - buckets, err := ttlmap.NewMap(maxSources) + buckets, err := ttlmap.NewConcurrent(maxSources) if err != nil { return nil, err } @@ -104,9 +102,6 @@ func (rl *rateLimiter) ServeHTTP(w http.ResponseWriter, r *http.Request) { logger.Infof("ignoring token bucket amount > 1: %d", amount) } - rl.bucketsMu.Lock() - defer rl.bucketsMu.Unlock() - var bucket *rate.Limiter if rlSource, exists := rl.buckets.Get(source); exists { bucket = rlSource.(*rate.Limiter)