Steeltoe icon indicating copy to clipboard operation
Steeltoe copied to clipboard

ILoadBalancer does not support this case when the service instance's hostname is not equal to ip

Open pengweiqhca opened this issue 5 years ago • 4 comments

Is your feature request related to a problem? Please describe.

When some service instance use special hostname rather than ip.

curl "http://127.0.0.1/xxx" -H "Host: bar.com"

Describe the solution you'd like

IServiceInstance.Uri should return scheme://ip:port/

-public virtual async Task<Uri> ResolveServiceInstanceAsync(Uri request)
+public virtual async Task ResolveServiceInstanceAsync(HttpRequestMessage request)
{
    var resolvedUri = availableServiceInstances[_random.Next(availableServiceInstances.Count)].Uri;
-   return new Uri(resolvedUri, request.PathAndQuery);
+   equest.RequestUri = new Uri(resolvedUri, request.RequestUri.PathAndQuery);
+   request.Headers.Host = resolvedUri.Host;
}

Describe alternatives you've considered

The hostname resolution result may be different with the ip, so the specified service instance cannot be accessed

Additional context

pengweiqhca avatar Sep 28 '20 10:09 pengweiqhca

Can you provide a sample app that illustrates this problem...

Thanks

dtillman avatar Oct 19 '20 16:10 dtillman

{
  "eureka:instance": {
    "instance": {
      //"preferIpAddress": true,
      "hostName": "bar.com",
      "ipAddress": "127.0.0.1",
      "port": 80
    }
  }
}

If preferIpAddress is true, instance uri is http://127.0.0.1. if preferIpAddress is false , instance uri is http://bar.com. When my site depoly in iis, binding with *:9054:bar.com, and bar.com resolved to multiple ips, the right way is

curl "http://127.0.0.1/xxx" -H "Host: bar.com"

pengweiqhca avatar Oct 20 '20 02:10 pengweiqhca

We will addressing with our Eureka updates in Epic #493

jkonicki avatar May 19 '21 15:05 jkonicki

This may not be possible with the data provided by service registrations

TimHess avatar Sep 25 '23 14:09 TimHess

This reads to me as a case where the app registering should set Eureka:Instance:RegistrationMethod to HostName so that the hostname will be used for the Uri and the IP address can be resolved via DNS. Please let us know if there is still a need to have both IP address and hostname specified

TimHess avatar Mar 28 '24 20:03 TimHess