Skip to content
Snippets Groups Projects
Commit 0a8e1bce authored by ale's avatar ale
Browse files

fix ip protocol detection: RemoteAddr is host:port

parent 009d7c75
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment