Skip to content

net: 1.19 DNS lookups broken on Windows if standard library built with CGO_ENABLED=0 #53490

Closed
@ianlancetaylor

Description

@ianlancetaylor

This bug is about the changes in Go 1.19 for DNS lookups on WIndows: https://go.dev/cl/409234 for #33097.

If the standard library is built with CGO_ENABLED=0, then in 1.18 we will still use the standard library on Windows, by calling functions like syscall.GetAddrInfoW. In both 1.18 and 1.19 building with CGO_ENABLED=0 will set netGo = true and will then set confVal.netGo = true. In 1.18 this has no real effect. In 1.19 this will mean that confVal.hostLookupOrder will return hostLookupDNS on Windows. That in turn means that (*Resolver).preferGoOverWindows will return true. That means that we will use the Go DNS routines, not the Windows functions.

Note that this can't be overridden by setting GODEBUG=netdns=cgo, as once netGo is set at initialization time everything else follows. This is a reasonable choice on Unix systems where building with CGO_ENABLED=0 means that the cgo functions are simply not available, but it's not a reasonable choice on Windows where the functions are always available.

One user-visible effect is that, since the Go lookup code on Windows has no way of looking at a /etc/hosts equivalent, looking up the address of localhost will fail.

We should make sure that Windows DNS functions will do the right thing when built with CGO_ENABLED=0 on Windows. I think they should default to using the Windows functions as before. That choice can be overridden with GODEBUG=netdns=go or by building with -tags=purego.

Or perhaps here is a different approach we could take, but definitely by default looking up localhost should work.

CC @bradfitz

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions