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: ability to replace Resolver impl #17554

Closed
kevinburke opened this issue Oct 23, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@kevinburke
Copy link
Contributor

commented Oct 23, 2016

The net.Resolver struct has the following TODOs:

// A Resolver looks up names and numbers.
//
// A nil *Resolver is equivalent to a zero Resolver.
type Resolver struct {
    // PreferGo controls whether Go's built-in DNS resolver is preferred
    // on platforms where it's available. It is equivalent to setting
    // GODEBUG=netdns=go, but scoped to just this resolver.
    PreferGo bool

    // TODO(bradfitz): optional interface impl override hook
    // TODO(bradfitz): Timeout time.Duration?
}

I'm interested in overriding the implementation. Specifically, I'd like to write a lookup function that ignores TTL's/returns the last good IP addresses if the DNS provider times out or returns an error instead of returning valid IP addresses. In theory that would help reliability during outages like Dyn's, where many sites were probably still available at their last known IP addresses, but the DNS resolver returned no responses for those sites.

I could override the DialContext currently, but that feels like overriding too much.

I'm happy to suggest ideas for an interface but I haven't done a ton of work with DNS and don't trust my instincts too much. @bradfitz, do you have ideas for the interface? I checked the commit and Github issues and couldn't find anything.

@quentinmit quentinmit changed the title Add a Lookup interface for Resolver net: ability to replace Resolver impl Oct 24, 2016

@quentinmit quentinmit added this to the Go1.8 milestone Oct 24, 2016

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Oct 24, 2016

Since Resolver is new in 1.8, now is our only chance to get this interface right.

I see there's Dialer.Resolver and net.DefaultResolver; maybe those variables should take an interface instead of a *Resolver? Then you could swap out the implementation that way, without adding anything to the Resolver struct.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Oct 24, 2016

It is a concrete type and not an interface on purpose. That lets us extend it with options, like we have with Dialer.

The TODO is about adding an interface or bag of funcs to the Resolver to call first, before the default implementation.

But I'd like to push that off until Go 1.9.

@bradfitz bradfitz modified the milestones: Go1.9, Go1.8 Oct 24, 2016

@kevinburke

This comment has been minimized.

Copy link
Contributor Author

commented Dec 24, 2016

FWIW, I tried working on an implementation of this that would let people override a http.Transport.DialContext. I ran into problems since I wanted to continue to use most of the default DialContext behavior, but it calls a ton of private functions in net (resolveAddrList, dialSerial, dialParallel). I gave up when I got to these functions in fd_poll_runtime.go

// runtimeNano returns the current value of the runtime clock in nanoseconds.
func runtimeNano() int64

func runtime_pollServerInit()
func runtime_pollOpen(fd uintptr) (uintptr, int)
func runtime_pollClose(ctx uintptr)
func runtime_pollWait(ctx uintptr, mode int) int
func runtime_pollWaitCanceled(ctx uintptr, mode int) int
func runtime_pollReset(ctx uintptr, mode int) int
func runtime_pollSetDeadline(ctx uintptr, d int64, mode int)
func runtime_pollUnblock(ctx uintptr)

@kisielk

This comment has been minimized.

Copy link
Contributor

commented Jan 11, 2017

Is this a dupe of #12503 ?

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

@kisielk, yes, thanks. I'll close this one.

@bradfitz bradfitz closed this Jan 11, 2017

@golang golang locked and limited conversation to collaborators Jan 11, 2018

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.