Skip to content

Commit

Permalink
feat: add sentinel error for no servers left in the backend pool (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewEdge authored Sep 27, 2023
1 parent be5cf38 commit bfc4fd9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion roundrobin/rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package roundrobin

import (
"errors"
"fmt"
"net/http"
"net/url"
Expand All @@ -10,6 +11,9 @@ import (
"github.com/vulcand/oxy/v2/utils"
)

// ErrNoServers indicates that there are no servers registered for the given Backend.
var ErrNoServers = errors.New("no servers in the pool")

// RoundRobin implements dynamic weighted round-robin load balancer http handler.
type RoundRobin struct {
mutex *sync.Mutex
Expand Down Expand Up @@ -116,7 +120,7 @@ func (r *RoundRobin) nextServer() (*server, error) {
defer r.mutex.Unlock()

if len(r.servers) == 0 {
return nil, fmt.Errorf("no servers in the pool")
return nil, ErrNoServers
}

// The algo below may look messy, but is actually very simple
Expand Down

0 comments on commit bfc4fd9

Please sign in to comment.