go: net: "cannot unmarshal DNS message" when using netdns=go under Windows/WSL2 running ubuntu 20.04

What version of Go are you using (go version)?

$ go version
go version go1.15.7 linux/amd64

Does this issue reproduce with the latest release?

Haven’t tried go1.16-rc1 or tip

What operating system and processor architecture are you using (go env)?

The problem has been reproduced with Microsoft Windows [Version 10.0.19042.746], WSL2 with Ubuntu 20.04

What did you do?

Run this program on WSL2 with Ubuntu 20.04. It is a very simple program, essentially just calling net.LookupHost

fmt.Printf("Looking up %q\n", host)
addrs, err := net.LookupHost(host)
if err != nil {
	fmt.Printf("- Failed with error: %v\n", err)
} else {
	for _, addr := range addrs {
		fmt.Printf("- Addr: %v\n", addr)
	}
}

What did you expect to see?

I expected it to resolve names correctly

What did you see instead?

$ ./host  prevasonline.sharepoint.com
Looking up "prevasonline.sharepoint.com"
- Failed with error: lookup prevasonline.sharepoint.com on 172.29.224.1:53: cannot unmarshal DNS message

$ GODEBUG=netdns=go ./host prevasonline.sharepoint.com
Looking up "prevasonline.sharepoint.com"
- Failed with error: lookup prevasonline.sharepoint.com on 172.29.224.1:53: cannot unmarshal DNS message

$ GODEBUG=netdns=cgo ./host prevasonline.sharepoint.com
Looking up "prevasonline.sharepoint.com"
- Addr: 13.107.136.9

This issue was originally from https://github.com/rclone/rclone/issues/4984 and @hstaugaard and @black-snow have reported it. I (@ncw) haven’t verified it personally since I don’t have Windows with WSL2.

This issue is superficially similar to https://github.com/golang/go/issues/37362 and https://github.com/golang/go/issues/36718 but the adddress in question doesn’t have any SRV records and we aren’t doing an SRV query, just HostLookup

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 18 (3 by maintainers)

Commits related to this issue

Most upvoted comments

can this be run with GODEBUG=netdns=go+2 and GODEBUG=netdns=cgo+2, also what if the DNS servers are changed (eg. to 8.8.8.8)?

$ GODEBUG=netdns=go+2 ./host prevasonline.sharepoint.com
Looking up "prevasonline.sharepoint.com"
go package net: GODEBUG setting forcing use of Go's resolver
go package net: hostLookupOrder(prevasonline.sharepoint.com) = files,dns
- Failed with error: lookup prevasonline.sharepoint.com on 172.29.128.1:53: cannot unmarshal DNS message

$ GODEBUG=netdns=cgo+2 ./host prevasonline.sharepoint.com
Looking up "prevasonline.sharepoint.com"
go package net: using cgo DNS resolver
go package net: hostLookupOrder(prevasonline.sharepoint.com) = cgo
- Addr: 13.107.136.9

Can’t test Googles DNS, no public DNS on work network.

I guess this didn’t get reopened, but #51127 has more information about this problem.