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: "cannot unmarshal DNS message" for SRV lookup #37362

Open
johnrichardrinehart opened this issue Feb 21, 2020 · 3 comments
Open

net: "cannot unmarshal DNS message" for SRV lookup #37362

johnrichardrinehart opened this issue Feb 21, 2020 · 3 comments
Milestone

Comments

@johnrichardrinehart
Copy link

@johnrichardrinehart johnrichardrinehart commented Feb 21, 2020

$ go version
go version go1.13.1 darwin/amd64

Does this issue reproduce with the latest release?

Yep.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

➜ ~ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/$USER/go/bin"
GOCACHE="/Users/$USER/Library/Caches/go-build"
GOENV="/Users/$USER/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/$USER/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wg/8x33rs4j5d7bgr5z58_4ql0m0000gn/T/go-build827220434=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I compiled the following program and executed the resultant program on an AWS EC2 instance passing the URI specified by the package vendor's documentation.

package main

import (
	"context"
	"flag"
	"log"
	"time"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
	"go.mongodb.org/mongo-driver/mongo/readpref"
)

func main() {
	uri := flag.String("uri", "mongodb://localhost:27017", "URI of the mongo server of interest")
	flag.Parse()
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	client, err := mongo.Connect(ctx, options.Client().ApplyURI(*uri))
	if err != nil {
		log.Fatalf("connection error: %s", err)
	}
	if err := client.Ping(ctx, readpref.Primary()); err != nil {
		log.Fatalf("pinging error: %s", err)
	}
	log.Println("exiting")
}

Compiled on my MacBook Pro using different go versions, all the way to gotip version

go version devel +ccb95b6492 Fri Feb 21 05:04:06 2020 +0000 darwin/amd64

Compiled using GOOS=linux GOARCH=amd64 go build . since I'm building for an Ubuntu 18.04 EC2 instance.

I then scped the binary to the remote machine.

What did you expect to see?

Using the mongo client binary to connect succeeds with proper DNS resolution. So, I expected that...

What did you see instead?

After sshing to the remote box I executed

./mongoConnectTest -uri=mongodb+srv://$USER:$PASSWORD@$HOST/$TESTDB

and received the following error.

2020/02/21 17:28:56 connection error: error parsing uri: lookup $HOST on 127.0.0.53:53: cannot unmarshal DNS message

Notes

I'm using a DNS seedlist provided by an SRV record to access a cluster of machines exposing a mongo interface to me. The documentation for that DNS resolution process by which a list of hostname:port pairs and connection options are acquired is here.

This problem seems related to net's inability to parse the resolved DNS entries. So, I've included the relevant DNS records below.

SRV record

ubuntu@ip-172-31-32-188:~$ dig SRV _mongodb._tcp.staging-vduzy.mongodb.net

; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> SRV _mongodb._tcp.staging-vduzy.mongodb.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4811
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;_mongodb._tcp.staging-vduzy.mongodb.net. IN SRV

;; ANSWER SECTION:
_mongodb._tcp.staging-vduzy.mongodb.net. 60 IN SRV 0 0 27017 staging-shard-00-02-vduzy.mongodb.net.
_mongodb._tcp.staging-vduzy.mongodb.net. 60 IN SRV 0 0 27017 staging-shard-00-00-vduzy.mongodb.net.
_mongodb._tcp.staging-vduzy.mongodb.net. 60 IN SRV 0 0 27017 staging-shard-00-01-vduzy.mongodb.net.

;; Query time: 9 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Feb 21 17:39:47 UTC 2020
;; MSG SIZE  rcvd: 206

TXT record

ubuntu@ip-172-31-32-188:~$ dig TXT staging-vduzy.mongodb.net

; <<>> DiG 9.11.3-1ubuntu1.11-Ubuntu <<>> TXT staging-vduzy.mongodb.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20788
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;staging-vduzy.mongodb.net.	IN	TXT

;; ANSWER SECTION:
staging-vduzy.mongodb.net. 60	IN	TXT	"authSource=admin&replicaSet=Staging-shard-0"

;; Query time: 23 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Fri Feb 21 17:40:15 UTC 2020
;; MSG SIZE  rcvd: 110
@toothrot toothrot changed the title [net] "cannot unmarshal DNS message" net: "cannot unmarshal DNS message" for SRV lookup Feb 21, 2020
@toothrot toothrot added this to the Backlog milestone Feb 21, 2020
@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Feb 21, 2020

Thanks for the detailed report. I think this has been seen previously at #10622 and #24870.

From the documentation for "go.mongodb.org/mongo-driver/mongo":

Potential DNS Issues
Building with Go 1.11+ and using connection strings with the "mongodb+srv"[1] scheme is incompatible with some DNS servers in the wild due to the change introduced in #10622. If you receive an error with the message "cannot unmarshal DNS message" while running an operation, we suggest you use a different DNS server.

https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo?tab=doc

It seems like closing this issue in favor of #24870 seems reasonable. Do you agree?

@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Feb 21, 2020

Also #36718 is related.

@johnrichardrinehart

This comment has been minimized.

Copy link
Author

@johnrichardrinehart johnrichardrinehart commented Feb 22, 2020

@toothrot Thanks for getting back to me. I should have included the version of the mongo client library that I was using.

➜   cat go.sum | grep mongo
go.mongodb.org/mongo-driver v1.1.3 h1:++7u8r9adKhGR+I79NfEtYrk2ktjenErXM99PSufIoI=
go.mongodb.org/mongo-driver v1.1.3/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=

I think the issue may be related to this package. I'm going to run a couple of tests in the next few days and will update if I discover anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.