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
Closed

net: ability to replace Resolver impl #17554

kevinburke opened this issue Oct 23, 2016 · 5 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@kevinburke
Copy link
Contributor

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 the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 24, 2016
@quentinmit quentinmit added this to the Go1.8 milestone Oct 24, 2016
@quentinmit
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

kisielk commented Jan 11, 2017

Is this a dupe of #12503 ?

@bradfitz
Copy link
Contributor

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

@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.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

5 participants