diff --git a/middlewares/cbreaker.go b/middlewares/cbreaker.go index d5c97d8f7..4a1859330 100644 --- a/middlewares/cbreaker.go +++ b/middlewares/cbreaker.go @@ -12,9 +12,12 @@ type CircuitBreaker struct { } // NewCircuitBreaker returns a new CircuitBreaker. -func NewCircuitBreaker(next http.Handler, expression string, options ...cbreaker.CircuitBreakerOption) *CircuitBreaker { - circuitBreaker, _ := cbreaker.New(next, expression, options...) - return &CircuitBreaker{circuitBreaker} +func NewCircuitBreaker(next http.Handler, expression string, options ...cbreaker.CircuitBreakerOption) (*CircuitBreaker, error) { + circuitBreaker, err := cbreaker.New(next, expression, options...) + if err != nil { + return nil, err + } + return &CircuitBreaker{circuitBreaker}, nil } func (cb *CircuitBreaker) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { diff --git a/server.go b/server.go index 8c92ae2f7..a8adaa288 100644 --- a/server.go +++ b/server.go @@ -507,7 +507,13 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo var negroni = negroni.New() if configuration.Backends[frontend.Backend].CircuitBreaker != nil { log.Debugf("Creating circuit breaker %s", configuration.Backends[frontend.Backend].CircuitBreaker.Expression) - negroni.Use(middlewares.NewCircuitBreaker(lb, configuration.Backends[frontend.Backend].CircuitBreaker.Expression, cbreaker.Logger(oxyLogger))) + cbreaker, err := middlewares.NewCircuitBreaker(lb, configuration.Backends[frontend.Backend].CircuitBreaker.Expression, cbreaker.Logger(oxyLogger)) + if err != nil { + log.Errorf("Error creating circuit breaker: %v", err) + log.Errorf("Skipping frontend %s...", frontendName) + continue frontend + } + negroni.Use(cbreaker) } else { negroni.UseHandler(lb) }