Open mateusz834 opened 1 year ago
cc @neild
Change https://go.dev/cl/455275 mentions this issue: net: rework the unified CNAME handling on unix
CC @rsc
@rsc do you have any opinions/thoughts on this? It would be nice to fix this issue at some point. Considering that you implemented the #50101 change, I would like to hear your opinion on this.
So there was a #50101 proposal to make the LookupCNAME consistent between unix/windows, or more concrete to make it send an explicit CNAME query, so that when the last CNAME doesn't have an ending A/AAAA record it returns the CNAME. So the change made the cgo version to use the res_search routines instead of getaddrinfo.
And that leads to some compat breaking changes that were made because of this change and some minor differences between linux/windows.
Current Issues: 1) when cgo fails the go resolver is being used (even for noSuchHost). This returns completed == false, so a fallback to go happens (lookupCNAME). EDIT: the go resolver will also send, second (unnecessary) CNAME. https://github.com/golang/go/blob/0d347544cbca0f42b160424f6bc2458ebcc7b3fc/src/net/cgo_unix.go#L296-L300 https://github.com/golang/go/blob/0d347544cbca0f42b160424f6bc2458ebcc7b3fc/src/net/lookup_unix.go#L102-L110 2) Windows returns the last CNAME in a CNAME chain, on unix the first is returned. (Before that change the last was returned, but only when A/AAAA existed, now always the first one (assuming that the CNAMEs are in order) 3) Unix no longer uses
getaddrinfo
, so when in nsswitch.conf is different in any way from:hosts: dns
it returns the wrong result (different that before that change), because of the fallback to go (Issue 1) this is not really noticeable, because the go resolver handles/etc/hosts
aliases correctly. (but for other nss modules it might cause problems (mdns, myhostname, resolve, ....)) 4) Cgo doesn't send also A/AAAA (like the go resolver does), so when removing the fallback to go resolver (Issue 1) then the tests start to fail, because not all domains in tests have CNAME (only A records). 5) https://github.com/golang/go/issues/44199#issuecomment-1417070233I made before a CL 455275 to try address that problems. The best solution to fix that is to do something like (for cgo resolver): Try with
getaddrinfo
, if it doesn't find anything (returnserrNoSuchHost
) then try withres_search
query for CNAME.CC @ianlancetaylor