Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: pure Go resolver(netdns) can not resolve hostname.local #35067

Open
YongHaoWu opened this issue Oct 22, 2019 · 6 comments

Comments

@YongHaoWu
Copy link

@YongHaoWu YongHaoWu commented Oct 22, 2019

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

go version go1.13.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/yonghao.hu/Library/Caches/go-build"
GOENV="/Users/yonghao.hu/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/yonghao.hu/mycode/go_dir_path"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/yonghao.hu/mycode/go_dir_path/src/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wf/nw471wh91nj2j_dsrfrk4htnjtqhhw/T/go-build666420423=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
	"fmt"
	"net"
)

func main() {
	dialer := &net.Dialer{
		LocalAddr: nil,
	}

	_, err := dialer.Dial("tcp", "yonghaohu-mac.local:4150")
	if err != nil {
		fmt.Println("resolve yonghaohu-mac.local failed: ", err)
	} else {
		fmt.Println("resolve myaliashost success")
	}
	_, err = dialer.Dial("tcp", "myaliashost:4150")
	if err != nil {
		fmt.Println("resolve myaliashost failed: ", err)
	}
	fmt.Println("resolve myaliashost success")
}

Just run GODEBUG=netdns=go+4 go run test.go

What did you expect to see?

Resolve to 127.0.0.1

What did you see instead?

resolve yonghaohu-mac.local failed: dial tcp: lookup yonghaohu-mac.local on 10.22.12.45:53: no such host

@bradfitz bradfitz changed the title pure Go resolver(netdns) can not resolve hostname.local net: pure Go resolver(netdns) can not resolve hostname.local Oct 22, 2019
@bradfitz

This comment has been minimized.

Copy link
Member

@bradfitz bradfitz commented Oct 22, 2019

Yes, that's known, as the docs at https://golang.org/pkg/net/#hdr-Name_Resolution imply, and we're unlikely to implement it.

If you need to resolve those names, use a different resolver.

@bradfitz bradfitz added this to the Unplanned milestone Oct 22, 2019
@YongHaoWu

This comment has been minimized.

Copy link
Author

@YongHaoWu YongHaoWu commented Oct 22, 2019

@bradfitz Hi, thanks for your reply . I know sth about this before writing the issue. Could u plz tell me why not to implement it ? What is the consideration?

@bradfitz

This comment has been minimized.

Copy link
Member

@bradfitz bradfitz commented Oct 22, 2019

It's a lot of code for very few users and the system DNS resolver is usually fine. The advantage of using the pure Go resolver is usually to avoid cgo and expensive threads being tied up during resolution, but that only matters when you have, say, tens of thousands of outstanding lookups. (e.g. you're a web crawler binary) But if you have tens of thousands of mDNS lookups outstanding, you probably have bigger problems on your LAN.

@alex-leonhardt

This comment has been minimized.

Copy link

@alex-leonhardt alex-leonhardt commented Nov 6, 2019

Hope you don't mind me hijacking this for quick question...

@bradfitz - what is the default behaviour in the absence of nsswitch.conf and a system resolver meant to be? I've had to "force" it to be used with -tags netgo, though I would have expected it to become the default since, well, there's no resolver or config that could try to use features that aren't supported?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 6, 2019

@alex-leonhardt The default behavior is system dependent. Which system are you asking about?

In general questions are better asked on a forum; see https://golang.org/wiki/Questions.

@alex-leonhardt

This comment has been minimized.

Copy link

@alex-leonhardt alex-leonhardt commented Nov 6, 2019

Thanks @ianlancetaylor - i'll ask in slack or the forums. My apologies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.