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: no way to set timeout for LookupAddr #16672

Closed
Tasssadar opened this issue Aug 11, 2016 · 7 comments

Comments

Projects
None yet
4 participants
@Tasssadar
Copy link

commented Aug 11, 2016

On Go 1.6, amd64 linux.

My application does a lot of lookups via net.LookupAddr. Sometimes, it gets stuck forever:

goroutine 114 [IO wait]:
net.runtime_pollWait(0x7f4e03df6000, 0x72, 0xc821d94400)
        /home/tassadar/go-linux-amd64-bootstrap/src/runtime/netpoll.go:160 +0x60
net.(*pollDesc).Wait(0xc8234f8140, 0x72, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/fd_poll_runtime.go:73 +0x3a
net.(*pollDesc).WaitRead(0xc8234f8140, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/fd_poll_runtime.go:78 +0x36
net.(*netFD).Read(0xc8234f80e0, 0xc821d94400, 0x200, 0x200, 0x0, 0x7f4e03e0e028, 0xc8200b20a0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/fd_unix.go:250 +0x23a
net.(*conn).Read(0xc8200bc080, 0xc821d94400, 0x200, 0x200, 0x200, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/net.go:172 +0xe4
net.(*UDPConn).readDNSResponse(0xc8200bc080, 0xc821b7f100, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/dnsclient_unix.go:52 +0xa5
net.exchange(0xc8223f4393, 0xd, 0xc823484380, 0x1a, 0xc8223f000c, 0x12a05f200, 0x0, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/dnsclient_unix.go:155 +0x4ea
net.tryOneName(0xc821b4e080, 0xc823484380, 0x1a, 0xc8223f000c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/dnsclient_unix.go:181 +0x2f3
net.lookup(0xc823484380, 0x1a, 0xc82348000c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/dnsclient_unix.go:318 +0x2eb
net.goLookupPTR(0xc8211d5bc4, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/dnsclient_unix.go:528 +0x167
net.lookupAddr(0xc8211d5bc4, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/lookup_unix.go:158 +0xfc
net.LookupAddr(0xc8211d5bc4, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/tassadar/go-linux-amd64-bootstrap/src/net/lookup.go:183 +0x4c

I tried to follow the code inside go, but there doesn't seem to be a way to set a timeout for this request.

@bradfitz bradfitz added this to the Go1.8Maybe milestone Aug 11, 2016

@mdlayher

This comment has been minimized.

Copy link
Member

commented Aug 16, 2016

Since there are nine net.Lookup* methods, I assume that adding a timeout for one of them would mean adding a timeout for each one?

@bradfitz

This comment has been minimized.

Copy link
Member

commented Aug 22, 2016

Yes. And we can't modify any existing API; we can only add.

I think the most future-proof option is to add a new type Resolver struct and add the 9 Lookup* methods to it, but taking a context.Context.

And then we can add options in the future to the Resolver type, like which upstream DNS server to use, whether to force cgo or not, etc.

/cc @ianlancetaylor @mdempsky @mikioh

@bradfitz

This comment has been minimized.

Copy link
Member

commented Aug 29, 2016

See also: #12503

@bradfitz bradfitz self-assigned this Aug 29, 2016

@mdlayher

This comment has been minimized.

Copy link
Member

commented Sep 1, 2016

I think the most future-proof option is to add a new type Resolver struct and add the 9 Lookup* methods to it, but taking a context.Context.

And then we can add options in the future to the Resolver type, like which upstream DNS server to use, whether to force cgo or not, etc.

I'd be happy to draft a proposal for this. Should I file a new issue when it's ready?

@bradfitz

This comment has been minimized.

Copy link
Member

commented Sep 20, 2016

@mdlayher, I sent https://golang.org/cl/29440 ... can you review that?

@mdlayher

This comment has been minimized.

Copy link
Member

commented Sep 20, 2016

Done. Thanks for that!

@gopherbot

This comment has been minimized.

Copy link

commented Sep 20, 2016

CL https://golang.org/cl/29440 mentions this issue.

@gopherbot gopherbot closed this in 2bc5f12 Sep 21, 2016

@golang golang locked and limited conversation to collaborators Sep 21, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.