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: LookupAddr changed result form in Go 1.5 #12189

Closed
rsc opened this issue Aug 18, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@rsc
Copy link
Contributor

commented Aug 18, 2015

Reported via email: LookupAddr("8.8.8.8") returned "google-public-dns-a.google.com." (with trailing dot) in all Go releases to date. In Go 1.5 candidate it returns "google-public-dns.a.google.com" (no trailing dot).

This was an intentional change, in CL 3420, but I believe it was a mistake. The argument made there was that the result was inconsistent depending on whether the C library resolver or the pure Go DNS resolver was being used. But Go 1.4 and earlier never used the C library resolver for this query. So the inconsistency indicated was only introduced after Go 1.4 and does not justify deviating from the Go 1.4 behavior.

I am still investigating and will post more details when I'm done, but right now it looks like we should put the dot back for consistency with all previous Go releases.

@rsc rsc self-assigned this Aug 18, 2015

@rsc rsc added this to the Go1.5 milestone Aug 18, 2015

@rsc

This comment has been minimized.

Copy link
Contributor Author

commented Aug 19, 2015

I checked all the Lookup functions. Here is a program to do that (comment out the NS code in Go 1):

package main

import (
    "bytes"
    "fmt"
    "net"
)

func main() {
    names, err := net.LookupAddr("8.8.8.8")
    fmt.Printf("LookupAddr(8.8.8.8) = %v, %v\n", names, err)

    cname, err := net.LookupCNAME("research.swtch.com")
    fmt.Printf("LookupCNAME(research.swtch.com) = %v, %v\n", cname, err)

    cname, err = net.LookupCNAME("www.mit.edu")
    fmt.Printf("LookupCNAME(www.mit.edu) = %v, %v\n", cname, err)

    mx, err := net.LookupMX("google.com")
    fmt.Printf("LookupMX(google.com) = %#v, %v\n", strmx(mx), err)

    ns, err := net.LookupNS("google.com")
    fmt.Printf("LookupNS(google.com) = %#v, %v\n", strns(ns), err)

    cname, addrs, err := net.LookupSRV("xmpp-server", "tcp", "google.com")
    fmt.Printf("LookupSRV(xmpp-server, tcp, google.com) = %v, %v, %v\n", cname, strsrv(addrs), err)

    txt, err := net.LookupTXT("google.com")
    fmt.Printf("LookupTXT(google.com) = %v, %v\n", txt, err)
}

func strmx(mxs []*net.MX) string {
    var buf bytes.Buffer
    sep := ""
    fmt.Fprintf(&buf, "[")
    for _, mx := range mxs {
        fmt.Fprintf(&buf, "%s%s:%d", sep, mx.Host, mx.Pref)
        sep = " "
    }
    fmt.Fprintf(&buf, "]")
    return buf.String()
}

func strns(nss []*net.NS) string {
    var buf bytes.Buffer
    sep := ""
    fmt.Fprintf(&buf, "[")
    for _, ns := range nss {
        fmt.Fprintf(&buf, "%s%s", sep, ns.Host)
        sep = " "
    }
    fmt.Fprintf(&buf, "]")
    return buf.String()
}

func strsrv(srvs []*net.SRV) string {
    var buf bytes.Buffer
    sep := ""
    fmt.Fprintf(&buf, "[")
    for _, srv := range srvs {
        fmt.Fprintf(&buf, "%s%s:%d:%d:%d", sep, srv.Target, srv.Port, srv.Priority, srv.Weight)
        sep = " "
    }
    fmt.Fprintf(&buf, "]")
    return buf.String()
}

Here are some Go versions running on Linux:

$ go1 version
go version go1
$ go1.1 version
go version go1.1.2 linux/amd64
$ go1.2 version
go version go1.2.2 linux/amd64
$ go1.3 version
go version go1.3.3 linux/amd64
$ go1.4 version
go version go1.4.2 linux/amd64
$ go version
go version devel +ee0658d Tue Aug 18 12:39:14 2015 -0400 linux/amd64
$

Compiled with plain make.bash (so cgo is enabled):

$ go1 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.1 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns3.google.com. ns2.google.com. ns4.google.com. ns1.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.2 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns2.google.com. ns3.google.com. ns4.google.com. ns1.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.3 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns3.google.com. ns2.google.com. ns4.google.com. ns1.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt4.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.4 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns1.google.com. ns3.google.com. ns4.google.com. ns2.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns4.google.com. ns1.google.com. ns3.google.com. ns2.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

Compiled with CGO_ENABLED=0 make.bash:

$ go1 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.1 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns3.google.com. ns2.google.com. ns4.google.com. ns1.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.2 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns3.google.com. ns2.google.com. ns4.google.com. ns1.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.3 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns1.google.com. ns3.google.com. ns2.google.com. ns4.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go1.4 run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com.], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns3.google.com. ns1.google.com. ns4.google.com. ns2.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

$ go run lookup.go
LookupAddr(8.8.8.8) = [google-public-dns-a.google.com], <nil>
LookupCNAME(research.swtch.com) = ghs.l.google.com., <nil>
LookupCNAME(www.mit.edu) = e9566.dscb.akamaiedge.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns1.google.com. ns3.google.com. ns2.google.com. ns4.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = _xmpp-server._tcp.google.com., [xmpp-server.l.google.com.:5269:5:0 alt3.xmpp-server.l.google.com.:5269:20:0 alt1.xmpp-server.l.google.com.:5269:20:0 alt4.xmpp-server.l.google.com.:5269:20:0 alt2.xmpp-server.l.google.com.:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>

It may be different on non-Linux systems, but it seems like literally every release of Go to date has had the trailing dot, while the current 1.5 tree has dropped it.

Furthermore, the dropping of the trailing dot in LookupAddr appears to be inconsistent with all the other functions, even in Go 1.5. (LookupTXT doesn't count, since it returns uninterpreted text, but I wanted to run all the Lookups.)

For both these reasons I think we should put the final dot back in.

I will prepare a CL.

@rsc

This comment has been minimized.

Copy link
Contributor Author

commented Aug 19, 2015

This is even worse than I thought. There is no code that takes the dot out from the Go lookups. The problem is that by default, and even when you set GODEBUG=netdns=go, the code tries the new C library wrappers before trying pure Go.

So not only did the result change, but now each blocked LookupAddr takes a full thread instead of a goroutine. That behavior definitely has to be rolled back.

@tpng

This comment has been minimized.

Copy link

commented Aug 19, 2015

Same test ran on go version go1.4.2 windows/386, Windows 7 64-bit.

LookupAddr(8.8.8.8) = [google-public-dns-a.google.com], <nil>
LookupCNAME(research.swtch.com) = ghs.google.com., <nil>
LookupCNAME(www.mit.edu) = www.mit.edu.edgekey.net., <nil>
LookupMX(google.com) = "[aspmx.l.google.com.:10 alt1.aspmx.l.google.com.:20 alt2.aspmx.l.google.com.:30 alt3.aspmx.l.google.com.:40 alt4.aspmx.l.google.com.:50]", <nil>
LookupNS(google.com) = "[ns2.google.com. ns3.google.com. ns4.google.com. ns1.google.com.]", <nil>
LookupSRV(xmpp-server, tcp, google.com) = google.com, [xmpp-server.l.google.com:5269:5:0 alt4.xmpp-server.l.google.com:5269:20:0 alt1.xmpp-server.l.google.com:5269:20:0 alt2.xmpp-server.l.google.com:5269:20:0 alt3.xmpp-server.l.google.com:5269:20:0], <nil>
LookupTXT(google.com) = [v=spf1 include:_spf.google.com ~all], <nil>
@gopherbot

This comment has been minimized.

Copy link

commented Aug 19, 2015

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

@gopherbot

This comment has been minimized.

Copy link

commented Nov 27, 2015

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

mikioh pushed a commit that referenced this issue Nov 28, 2015

Mikio Hara
net: force LookupAddr results to be rooted DNS paths even in the case…
… of local source

The builtin name resolver using various resolution techniques is a bit
complicated and we sometimes fotget to take care of all the go and cgo
code paths and exchanging information to local and remote sources. This
change makes LookupAddr return absolute domain names even in the case of
local source.

Updates #12189.
Fixes #12240.

Change-Id: Icdd3375bcddc7f5d4d3b24f134d93815073736fc
Reviewed-on: https://go-review.googlesource.com/17216
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@gopherbot

This comment has been minimized.

Copy link

commented Dec 4, 2015

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

mikioh pushed a commit that referenced this issue Dec 5, 2015

net: adjust Lookup API test cases
This change makes existing Lookup API test cases conform to the new
return value form that all the Lookup APIs except LookupTXT must return
a single or multiple absolute domain names.

Updates #12189.
Fixes #12193.

Change-Id: I03ca09be5bff80e818fbcdc26039daa33d5440a8
Reviewed-on: https://go-review.googlesource.com/17411
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>

@golang golang locked and limited conversation to collaborators Dec 14, 2016

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.