1
0
mirror of https://github.com/golang/go synced 2024-10-02 22:31:22 -06:00

net: ensure identical queries are not sent multiple times in builtin stub resolver

Prevents non-rooted queries with > ndots dots from being tried twice on error.
Fixes #8616.

Benchmark results on linux/amd64
benchmark                        old ns/op    new ns/op    delta
BenchmarkGoLookupIPNoSuchHost      8212394      4413293  -46.26%

benchmark                       old allocs   new allocs    delta
BenchmarkGoLookupIPNoSuchHost          216          108  -50.00%

benchmark                        old bytes    new bytes    delta
BenchmarkGoLookupIPNoSuchHost        17460         8726  -50.02%

LGTM=iant, mikioh.mikioh
R=golang-codereviews, iant, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/137870043
This commit is contained in:
Alex A Skinner 2014-08-30 07:50:50 +09:00 committed by Mikio Hara
parent 858c57f5bd
commit 854dbb7fdc
2 changed files with 15 additions and 12 deletions

View File

@ -310,13 +310,10 @@ func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err error)
} }
// Can try as ordinary name. // Can try as ordinary name.
cname, addrs, err = tryOneName(cfg.dnsConfig, rname, qtype) cname, addrs, err = tryOneName(cfg.dnsConfig, rname, qtype)
if err == nil { if rooted || err == nil {
return return
} }
} }
if rooted {
return
}
// Otherwise, try suffixes. // Otherwise, try suffixes.
for i := 0; i < len(cfg.dnsConfig.search); i++ { for i := 0; i < len(cfg.dnsConfig.search); i++ {
@ -330,15 +327,15 @@ func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err error)
} }
} }
// Last ditch effort: try unsuffixed. // Last ditch effort: try unsuffixed only if we haven't already,
rname := name // that is, name is not rooted and has less than ndots dots.
if !rooted { if count(name, '.') < cfg.dnsConfig.ndots {
rname += "." cname, addrs, err = tryOneName(cfg.dnsConfig, name+".", qtype)
} if err == nil {
cname, addrs, err = tryOneName(cfg.dnsConfig, rname, qtype) return
if err == nil { }
return
} }
if e, ok := err.(*DNSError); ok { if e, ok := err.(*DNSError); ok {
// Show original name passed to lookup, not suffixed one. // Show original name passed to lookup, not suffixed one.
// In general we might have tried many suffixes; showing // In general we might have tried many suffixes; showing

View File

@ -217,3 +217,9 @@ func TestReloadResolvConfChange(t *testing.T) {
r.SetConf("nameserver 8.8.4.4") r.SetConf("nameserver 8.8.4.4")
r.WantServers([]string{"[8.8.4.4]"}) r.WantServers([]string{"[8.8.4.4]"})
} }
func BenchmarkGoLookupIPNoSuchHost(b *testing.B) {
for i := 0; i < b.N; i++ {
goLookupIP("some.nonexistent")
}
}