diff --git a/cmd/endpoint.go b/cmd/endpoint.go index 9a1f2ce9b..e7c4dc3f5 100644 --- a/cmd/endpoint.go +++ b/cmd/endpoint.go @@ -702,6 +702,17 @@ func CreateEndpoints(serverAddr string, foundLocal bool, args ...[]string) (Endp } } + // Add missing port in all endpoints. + for i := range endpoints { + _, port, err := net.SplitHostPort(endpoints[i].Host) + if err != nil { + endpoints[i].Host = net.JoinHostPort(endpoints[i].Host, serverAddrPort) + } else if endpoints[i].IsLocal && serverAddrPort != port { + // If endpoint is local, but port is different than serverAddrPort, then make it as remote. + endpoints[i].IsLocal = false + } + } + // All endpoints are pointing to local host if len(endpoints) == localEndpointCount { // If all endpoints have same port number, Just treat it as local erasure setup @@ -718,17 +729,6 @@ func CreateEndpoints(serverAddr string, foundLocal bool, args ...[]string) (Endp // This means it is DistErasure setup. } - // Add missing port in all endpoints. - for i := range endpoints { - _, port, err := net.SplitHostPort(endpoints[i].Host) - if err != nil { - endpoints[i].Host = net.JoinHostPort(endpoints[i].Host, serverAddrPort) - } else if endpoints[i].IsLocal && serverAddrPort != port { - // If endpoint is local, but port is different than serverAddrPort, then make it as remote. - endpoints[i].IsLocal = false - } - } - uniqueArgs := set.NewStringSet() for _, endpoint := range endpoints { uniqueArgs.Add(endpoint.Host) diff --git a/cmd/endpoint_test.go b/cmd/endpoint_test.go index 4925f0617..645cf8d3f 100644 --- a/cmd/endpoint_test.go +++ b/cmd/endpoint_test.go @@ -252,10 +252,10 @@ func TestCreateEndpoints(t *testing.T) { }, // DistErasure Setup with URLEndpointType {":9000", [][]string{{"http://localhost/d1", "http://localhost/d2", "http://localhost/d3", "http://localhost/d4"}}, ":9000", Endpoints{ - Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d1"}, IsLocal: true}, - Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d2"}, IsLocal: true}, - Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d3"}, IsLocal: true}, - Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost", Path: "/d4"}, IsLocal: true}, + Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d1"}, IsLocal: true}, + Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d2"}, IsLocal: true}, + Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d3"}, IsLocal: true}, + Endpoint{URL: &url.URL{Scheme: "http", Host: "localhost:9000", Path: "/d4"}, IsLocal: true}, }, ErasureSetupType, nil}, // DistErasure Setup with URLEndpointType having mixed naming to local host. {"127.0.0.1:10000", [][]string{{"http://localhost/d1", "http://localhost/d2", "http://127.0.0.1/d3", "http://127.0.0.1/d4"}}, "", Endpoints{}, -1, fmt.Errorf("all local endpoints should not have different hostnames/ips")},