This change introduces a bit more determinism in the behavior of the name resolver.
There were a few issues:
we were using the capacity of the results slice instead of its length to determine how many addresses may be returned
we sliced the ip list to the first N elements before checking for the hints, which could result in only having results of the wrong address family (then failing name resolution)
I also added a partial sort of the results so that we put the AF_INET addresses first when they are mixed with AF_INET6 due to the hint being AF_UNSPEC, this helps keep the behavior deterministic; for example, if the client uses the first address that it is returned, it doesn't result in sometimes connecting to an IPv4 and sometimes an IPv6.
This change introduces a bit more determinism in the behavior of the name resolver.
There were a few issues:
I also added a partial sort of the results so that we put the AF_INET addresses first when they are mixed with AF_INET6 due to the hint being AF_UNSPEC, this helps keep the behavior deterministic; for example, if the client uses the first address that it is returned, it doesn't result in sometimes connecting to an IPv4 and sometimes an IPv6.