Fix rate limiting and SSE
This commit is contained in:
parent
2036518813
commit
e6e026f420
1 changed files with 2 additions and 7 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/containous/traefik/v2/pkg/config/dynamic"
|
||||
|
@ -35,7 +34,6 @@ type rateLimiter struct {
|
|||
sourceMatcher utils.SourceExtractor
|
||||
next http.Handler
|
||||
|
||||
bucketsMu sync.Mutex
|
||||
buckets *ttlmap.TtlMap // actual buckets, keyed by source.
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue