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

proposal: net: add context/timeout/deadline for Resolve* #18947

Closed
LionNatsu opened this issue Feb 5, 2017 · 2 comments
Closed

proposal: net: add context/timeout/deadline for Resolve* #18947

LionNatsu opened this issue Feb 5, 2017 · 2 comments

Comments

@LionNatsu
Copy link
Contributor

LionNatsu commented Feb 5, 2017

To resolve an address, it needs a communication between local host and name server. When the routes changed or something else makes the address being unreachable, or there is loss of UDP datagram, there will be a high delay (maybe the goroutine will never wake up again).

What I can do now is use net.DialContext() with a deadline or net.Dialer. But when I want to only resolve the host name/domain, net.Resolve*Addr() or net.Lookup*() never timeout.

I read source code of net and I found net.Resolve*Addr() does have some code about context:

/src/net/tcpsock.go:64

    56	func ResolveTCPAddr(net, addr string) (*TCPAddr, error) {
    57		switch net {
    58		case "tcp", "tcp4", "tcp6":
    59		case "": // a hint wildcard for Go 1.0 undocumented behavior
    60			net = "tcp"
    61		default:
    62			return nil, UnknownNetworkError(net)
    63		}
    64		addrs, err := internetAddrList(context.Background(), net, addr)
    65		if err != nil {
    66			return nil, err
    67		}
    68		return addrs.first(isIPv4).(*TCPAddr), nil
    69	}

Can we export the context argument?

Maybe add something like net.ResolveTCPAddrContext() ? or an interface called, maybe, Resolver?


Please answer these questions before submitting your issue. Thanks!

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

1.7.4

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build628929889=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
@LionNatsu
Copy link
Contributor Author

Possibly dup of #6340 (6 Sep 2013). Should I leave this issue open?

@LionNatsu
Copy link
Contributor Author

Okay... there is net.Resolver in 1.8 . Closing.

@golang golang locked and limited conversation to collaborators Feb 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants