-
Notifications
You must be signed in to change notification settings - Fork 11
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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)) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add a test for when:
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 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) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM