Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Dns.GetHostEntry, it might not return the original IP address #728

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Discovery.Azure.Model;
using Akka.Event;
using Akka.Util.Internal;
Expand Down Expand Up @@ -123,14 +124,19 @@ private bool Initializing(object message)
case Start _:
try
{
var entry = Dns.GetHostEntry(_settings.HostName);
_host = entry.HostName;
_address = entry.AddressList
.First(i =>
!Equals(i, IPAddress.Any) &&
!Equals(i, IPAddress.Loopback) &&
!Equals(i, IPAddress.IPv6Any) &&
!Equals(i, IPAddress.IPv6Loopback));
if (IPAddress.TryParse(_settings.HostName, out _address))
{
if (_address.Equals(IPAddress.Any) || _address.Equals(IPAddress.IPv6Any))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

throw new ConfigurationException($"IPAddress.Any or IPAddress.IPv6Any cannot be used as host address. Was: {_settings.HostName}");

_host = Dns.GetHostName();
}
else
{
_host = _settings.HostName;
_address = Dns.GetHostAddresses(_host)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a test for when:

  1. Hostname is valid for routing (externally)
  2. Hostname is not assigned to anything locally via DHCP

This is an extremely common scenario in cloud environments outside of K8s since much of the network address translation happens at the software level above the VM. It's why we have the public-hostname and public-port settings in Akka.Remote.

I would not worry about this right now though - save it for integration testing with Azure App Service.

.First(i => !Equals(i, IPAddress.Any) && !Equals(i, IPAddress.IPv6Any));
}
}
catch (Exception ex)
{
Expand Down