Fix bug when Dns.GetHostEntry() returns addresses in unexpected order #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We ran into an issue where our metrics weren't sending from some servers, but were sending from others. We had difficulty tracking it down because no exceptions were showing up in any of our logs.
It turns out that the issue was with IP address resolution. After calling Dns.GetHostEntry() in StatsUDP.GetIpv4Address, the code would then return the last element in the array, assuming that it would be the IPv4 address. However, on the servers where we were encountering this issue, we discovered that Dns.GetHostEntry() was returning IPv4 first, and IPv6 last. This would then cause errors when metrics got sent over UDP, which was being silently caught and squashed in the try-catch statement in Statsd.Send().
My proposed fix is to iterate through the returned addresses in reverse to find an IPv4 address. If no IPv4 address is found, then generate the same exception that would have been squashed at send-time, but allow the user to catch and handle it themselves.
This issue was previously documented by #4