From 0a8e1bceabf734e72267ef396f06f75d18a0ccd8 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Fri, 16 Oct 2015 23:44:04 +0100 Subject: [PATCH] fix ip protocol detection: RemoteAddr is host:port --- fe/http.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fe/http.go b/fe/http.go index f5d743de..0e0b8e8e 100644 --- a/fe/http.go +++ b/fe/http.go @@ -122,8 +122,11 @@ func NewHTTPRedirector(client *autoradio.Client, domain, lbspec, staticDir, temp // Pick a random IP with a protocol appropriate to the request (based // on the remote address). func randomIPForRequest(ips []net.IP, r *http.Request) net.IP { - remoteAddr := net.ParseIP(r.RemoteAddr) - isV6 := (remoteAddr != nil && (remoteAddr.To4() == nil)) + isV6 := false + if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil { + remoteAddr := net.ParseIP(host) + isV6 = (remoteAddr != nil && (remoteAddr.To4() == nil)) + } return randomIPByProto(ips, isV6) } @@ -145,6 +148,8 @@ func (h *HTTPRedirector) pickActiveNode(r *http.Request) net.IP { return randomIPForRequest(result.IP, r) } +// Periodically update the active nodes information in the load +// balancer. Requests will then use the cached data. func (h *HTTPRedirector) lbUpdater() { for range time.NewTicker(2 * time.Second).C { nodes, err := h.client.GetNodes() -- GitLab