diff --git a/fe/http.go b/fe/http.go index f5d743de37e29f7491a0aaece461e1799ccd36ec..0e0b8e8e5de0bbe547fa259747308b17b063aafa 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()