Prevent error logging when TCP WRR pool is empty

This commit is contained in:
Kevin Pollet 2024-08-12 14:08:05 +02:00 committed by GitHub
parent 0eb0a15aa1
commit e7dc097901
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,8 @@ import (
"github.com/traefik/traefik/v2/pkg/log" "github.com/traefik/traefik/v2/pkg/log"
) )
var errNoServersInPool = errors.New("no servers in the pool")
type server struct { type server struct {
Handler Handler
weight int weight int
@ -34,8 +36,10 @@ func (b *WRRLoadBalancer) ServeTCP(conn WriteCloser) {
b.lock.Unlock() b.lock.Unlock()
if err != nil { if err != nil {
if !errors.Is(err, errNoServersInPool) {
log.WithoutContext().Errorf("Error during load balancing: %v", err) log.WithoutContext().Errorf("Error during load balancing: %v", err)
conn.Close() }
_ = conn.Close()
return return
} }
@ -91,7 +95,7 @@ func gcd(a, b int) int {
func (b *WRRLoadBalancer) next() (Handler, error) { func (b *WRRLoadBalancer) next() (Handler, error) {
if len(b.servers) == 0 { if len(b.servers) == 0 {
return nil, errors.New("no servers in the pool") return nil, errNoServersInPool
} }
// The algo below may look messy, but is actually very simple // The algo below may look messy, but is actually very simple