Fix localhost handling in DnsLookupIpEndpointSource #121
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.
While investigating writing some integration tests to help avoid issues like #110 in the future and assist with the work for 4.0.0, I found a bug in the DNS handling for
"localhost"
.If you run statsd locally in the default configuration, it listens at
127.0.0.1:8125
using IPv4.However, on a machine that supports both IPv4 and IPv6, the first address returned by
Dns.GetHostAddressesAsync()
may be an IPv6 address.This causes metrics to be sent to
::1
instead of127.0.0.1
, where there is nothing listening, so metrics are silently dropped. This would found by my integration test as the statsd admin interface on8126
did not report back that the metrics being sent were being received.This PR fixes this by preferring the first address with an address family of
AddressFamily.InterNetwork
as that's the intuitive default behaviour for statsd for "pit-of-success".We could maybe extend things in the future to support preferring IPv6 through configuration, but that's already achievable today by using
SimpleIpEndpoint
instead.