You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proxy middleware can panic when the balancer has no targets #2976
ProxyWithConfig can panic when the balancer has no targets.
The built-in balancers return nil when their target list is empty. The proxy middleware then passes that nil target to proxyHTTP / proxyRaw, which can panic.
One way to hit this is to remove the last target with RemoveTarget.
I expected the middleware to return a proxy error, such as 502 Bad Gateway, instead of panicking.
Working code to debug
targetURL, _:=url.Parse("http://127.0.0.1:8080")
balancer:=middleware.NewRoundRobinBalancer([]*middleware.ProxyTarget{
{Name: "target", URL: targetURL},
})
e:=echo.New()
e.Use(middleware.Proxy(balancer))
// Later, from code that updates proxy targets at runtime:balancer.RemoveTarget("target")
// The next proxied request can panic because the balancer returns nil.
### Version/commit
v4.15.xandv5.1.x
Activity