-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Comments
Thanks for the detailed report. I think this has been seen previously at #10622 and #24870. From the documentation for
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? |
Also #36718 is related. |
@toothrot Thanks for getting back to me. I should have included the version of the
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. |
@toothrot I believe we have another user experiencing this issue with the Also, my understanding is that the revert will temporarily solve this issue and #24870 will update the code to correctly follow RFC 6762. Is this correct? |
Was facing the same issue with |
@toothrot @divjotarora @Wolf00 I failed to update the results of my tests. I actually managed to get the original code to work (using a connection URI string of the form @Wolf00 My build was using |
@johnrichardrinehart Thanks for the update. Any ideas why adding the CA certs fixed the DNS issue? |
Actually, no. I'm having a hard time, looking through the |
Ah, I remember now. The connection string defaults to Also, see this. |
@johnrichardrinehart I'm happy to continue this discussion elsewhere, but you're right that using an SRV URI internally sets TLS to true. I'm not seeing lack of certs would result in an DNS resolution error though. That part of the code only calls |
@divjotarora I agree. The issue seems unrelated to TLS certificates. However, I've done some more testing and TLS certificates are, indeed, necessary for my use case: I'm connecting to a Mongo Atlas cluster which requires TLS/SSL - so, if they aren't available (Docker image built on I've ran 3 more tests which I think will shed some light on the issue, although I'm still confused as to the root problem. The first two tests fail (in different ways) and the last test succeeds.
The OS details (for Test 1) are: ubuntu@some-machine:~/dnstest$ uname -a
Linux ip-172-31-46-120 4.15.0-1057-aws #59-Ubuntu SMP Wed Dec 4 10:02:00 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@some-machine:~/dnstest$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.3 LTS
Release: 18.04
Codename: bionic The problem may be related to the I can run other tests as desired. All tests use source code within one directory whose contents are: ubuntu@some-machine:~$ tree dnstest
dnstest
├── Dockerfile
├── Dockerfile_withTLS
├── go.mod
├── go.sum
└── main.go Their contents are, respectively, Dockerfile (Test 2)FROM golang:1.14.2
ENV GOPATH=/go
ARG BUILDDIR=/build
COPY . $BUILDDIR
WORKDIR $BUILDDIR
RUN go get .
RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -a -o dnstest .
FROM scratch
COPY --from=0 /build/dnstest /dnstest
ENTRYPOINT ["/dnstest"] Dockerfile_withTLS (Test 3, only different in the 2nd-to-last line)FROM golang:1.14.2
ENV GOPATH=/go
ARG BUILDDIR=/build
COPY . $BUILDDIR
WORKDIR $BUILDDIR
RUN go get .
RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -a -o dnstest .
FROM scratch
COPY --from=0 /build/dnstest /dnstest
COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ENTRYPOINT ["/dnstest"] go.modmodule dnstest
go 1.14
require go.mongodb.org/mongo-driver v1.3.2 go.sumgit.luolix.top/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/klauspost/compress v1.9.5 h1:U+CaK85mrNNb4k8BNOfgJtJ/gr6kswUCFj6miSzVC6M=
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc h1:n+nNi93yXLkJvKwXNP9d55HC7lGK4H/SRcwB5IaUZLo=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
go.mongodb.org/mongo-driver v1.3.2 h1:IYppNjEV/C+/3VPbhHVxQ4t04eVW0cLp0/pNdW++6Ug=
go.mongodb.org/mongo-driver v1.3.2/go.mod h1:MSWZXKOynuguX+JSvwP8i+58jYCXxbia8HS3gZBapIE=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 h1:8dUaAV7K4uHsF56JQWkprecIQKdPHtR9jCHF5nB8uzc=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= main.go (Test 1, and used in both Dockerfiles)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"
"go.mongodb.org/mongo-driver/version"
)
func main() {
uri := flag.String("uri", "mongodb://localhost:27017", "URI of the mongo server of interest")
flag.Parse()
log.Printf("mongo-go-driver version: %s", version.Driver)
opts := options.Client().ApplyURI(*uri)
if err := opts.Validate(); err != nil {
log.Fatalf("invalid options: %s", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
client, err := mongo.Connect(ctx, opts)
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("success... exiting")
} Note: Credentials have been redacted for security reasons. However, credentials were supplied for each test in the same way. Test 1 (Native Binary)Setup/Input
Result/Output (credentials redacted)ubuntu@some-machine:~/dnstest$ ./dnstest -uri="mongodb+srv://<user>:<password>@staging.vduzy.mongodb.net"
2020/04/17 20:30:48 mongo-go-driver version: v1.3.2
2020/04/17 20:30:48 invalid options: error parsing uri: lookup staging.vduzy.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message Test 2 (Dockerized without TLS certificates)Setup/Input
Result/Outputubuntu@some-machine:~/dnstest$ docker run dnstest:latest -uri="mongodb+srv://<user>:<password>@staging.vduzy.mongodb.net"
2020/04/17 20:34:14 mongo-go-driver version: v1.3.2
2020/04/17 20:34:15 pinging error: context deadline exceeded Test 3 (Dockerized with TLS certificates)Setup/Input
Result/Outputubuntu@some-machine:~/dnstest$ sudo docker run dnstest_tls:latest
-uri="mongodb+srv://<user>:<password>@staging.vduzy.mongodb.net"
2020/04/17 20:37:02 mongo-go-driver version: v1.3.2
2020/04/17 20:37:02 success... exiting |
I am experiencing the same issue with mongodump 4.2 on Ubuntu 18.04 AWS EC2 instance.
If I add 8.8.8.8 as first DNS server, then it works! |
This doesn't sound like a @ismailyenigul It looks like your DNS resolution using |
It seems something wrong between Ubuntu 18.04 systemd and mongodump go library version. |
Were you having DNS issues ( |
I'm having same issue with SRV lookups proxied from systemd-resolved to consul. drill/dig work just fine:
upd: This most likely relates to systemd/systemd#9828 |
No, all good with that tools. Only mongodump does not work. |
edit: I just noticed #51127 was already fixed. I'm currently facing that issue in a WSL2 environment using Go 1.18 beta 2. The package error(*net.DNSError) *{
Err: "cannot unmarshal DNS message",
Name: "management.azure.com",
Server: "172.25.160.1:53",
IsTimeout: false,
IsTemporary: false,
IsNotFound: false,},} $ dig management.azure.com 172.25.160.1
; <<>> DiG 9.16.1-Ubuntu <<>> management.azure.com 172.25.160.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 813
;; flags: qr rd ad; QUERY: 1, ANSWER: 7, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;management.azure.com. IN A
;; ANSWER SECTION:
management.azure.com. 0 IN CNAME management.privatelink.azure.com.
management.privatelink.azure.com. 0 IN CNAME arm-frontdoor-prod.trafficmanager.net.
arm-frontdoor-prod.trafficmanager.net. 0 IN CNAME germanywestcentral.management.azure.com.
germanywestcentral.management.azure.com. 0 IN CNAME arm-frontdoor-germanywestcentral.trafficmanager.net.
arm-frontdoor-germanywestcentral.trafficmanager.net. 0 IN CNAME germanywestcentral.cs.management.azure.com.
germanywestcentral.cs.management.azure.com. 0 IN CNAME rpfd-germanywestcentral.cloudapp.net.
rpfd-germanywestcentral.cloudapp.net. 0 IN A 51.116.156.32
;; Query time: 10 msec
;; SERVER: 172.25.160.1#53(172.25.160.1)
;; WHEN: Sun Mar 06 15:13:43 CET 2022
;; MSG SIZE rcvd: 632
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25454
;; flags: qr rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available
;; QUESTION SECTION:
;172.25.160.1. IN A
;; ANSWER SECTION:
172.25.160.1. 0 IN A 172.25.160.1
;; Query time: 0 msec
;; SERVER: 172.25.160.1#53(172.25.160.1)
;; WHEN: Sun Mar 06 15:13:43 CET 2022
;; MSG SIZE rcvd: 58 I suspect the problem isn't specific to the aforementioned domain. Switching the primary DNS server to |
For MongoDB Atlas serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1)
clientOptions := options.Client().
ApplyURI("mongodb://username:password@prefix0.mongodb.net:27017,prefix1.mongodb.net:27017,prefix2.mongodb.net:27017/?retryWrites=true&w=majority&replicaSet=atlas-zhqegh-shard-0&tls=true").
SetServerAPIOptions(serverAPIOptions)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
client, err := mongo.Connect(ctx, clientOptions)
if err != nil {
log.Fatal(err)
} To clarify the MongoDB Atlas replicaSet and hosts you can for instance utilize MongoDB Compass: just connect to the cluster and you will see all that data. |
just got the same problem after updating my golang to go version go1.17.11 linux/amd64
gives me
at the same time if i checkout SRV records using
Upd: just noticed the date of this issue. looks too old. I'm going to create the new one |
For anyone still got this error, it's happen when you're using DNS from shared network like coffee shop or mobile phone hotspot. I suggest to use an other "deep" DNS server. |
Thank you @jmsmss, your suggestion has saved my day. Providing some additional interesting details (just in case). This Python code works with "any" DNS: import srvlookup #pip install srvlookup
import sys
import dns.resolver #pip install dnspython
host = None
if len(sys.argv) > 1 :
host = sys.argv[1]
if host :
services = srvlookup.lookup("mongodb", domain=host)
for i in services:
print("%s:%i" % (i.hostname, i.port))
for txtrecord in dns.resolver.query(host, 'TXT'):
print("%s: %s" % ( host, txtrecord))
else:
print("No host specified") Here is the Golang code created based on that Python code (which seems to be pickier about the DNS server): package main
import (
"fmt"
"net"
"os"
)
func main() {
// Get the hostname from the command line argument
host := os.Args[1]
// Look up the SRV records for the hostname
_, addrs, err := net.LookupSRV("mongodb", "tcp", host)
if err != nil {
fmt.Println(err)
return
}
// Print the SRV records
for _, addr := range addrs {
fmt.Printf("%s:%d\n", addr.Target, addr.Port)
}
// Look up the TXT records for the hostname
txts, err := net.LookupTXT(host)
if err != nil {
fmt.Println(err)
return
}
// Print the TXT records
for _, txt := range txts {
fmt.Printf("%s: %s\n", host, txt)
}
} The Python code was taken from this article. I was testing both codes (Golang and Python) from the same virtual machine: Manjaro Linux 22.0.0.
Conclusion
The error happens at func (n *Name) unpackCompressed(msg []byte, off int, allowCompression bool) (int, error) {
// currOff is the current working offset.
currOff := off
// newOff is the offset where the next record will start. Pointers lead
// to data that belongs to other names and thus doesn't count towards to
// the usage of this name.
newOff := off
// ptr is the number of pointers followed.
var ptr int
// Name is a slice representation of the name data.
name := n.Data[:0]
Loop:
for {
if currOff >= len(msg) {
return off, errBaseLen
}
c := int(msg[currOff])
currOff++
switch c & 0xC0 {
case 0x00: // String segment
if c == 0x00 {
// A zero length signals the end of the name.
break Loop
}
endOff := currOff + c
if endOff > len(msg) {
return off, errCalcLen
}
name = append(name, msg[currOff:endOff]...)
name = append(name, '.')
currOff = endOff
case 0xC0: // Pointer
if !allowCompression {
// ===========> THE ERROR IS HAPPENING HERE
return off, errCompressedSRV
}
if currOff >= len(msg) {
return off, errInvalidPtr
}
c1 := msg[currOff]
currOff++
if ptr == 0 {
newOff = currOff
}
// Don't follow too many pointers, maybe there's a loop.
if ptr++; ptr > 10 {
return off, errTooManyPtr
}
currOff = (c^0xC0)<<8 | int(c1)
default:
// Prefixes 0x80 and 0x40 are reserved.
return off, errReserved
}
}
if len(name) == 0 {
name = append(name, '.')
}
if len(name) > len(n.Data) {
return off, errCalcLen
}
n.Length = uint8(len(name))
if ptr == 0 {
newOff = currOff
}
return newOff, nil
} WiresharkProviding below DNS responses from different DNS servers (1.1.1.1 and 192.168.88.1). 1.1.1.1 (DNS response)Summary:----
# Packet 1 from /var/folders/02/prfbfy6n5mg4mvt5kd5yjq_w0000gn/T/wireshark_Wi-FiUZI4X1.pcapng
- 131
- 1.932045
- 1.1.1.1
- 192.168.88.242
- DNS
- 305
- Standard query response 0xbe07 SRV _mongodb._tcp.<REPLACED>.<REPLACED>.mongodb.net SRV 0 0 27017 <REPLACED>.<REPLACED>.mongodb.net SRV 0 0 27017 <REPLACED>.<REPLACED>.mongodb.net SRV 0 0 27017 <REPLACED>.<REPLACED>.mongodb.net OPT HEX dump:
192.168.88.1 (DNS response)Summary:----
# Packet 17 from /var/folders/02/prfbfy6n5mg4mvt5kd5yjq_w0000gn/T/wireshark_Wi-FiZ2EBY1.pcapng
- 1121
- 5.778839
- 192.168.88.1
- 192.168.88.242
- DNS
- 249
- Standard query response 0x2ad6 SRV _mongodb._tcp.<REPLACED>.<REPLACED>.mongodb.net SRV 0 0 27017 <REPLACED>.<REPLACED>.mongodb.net SRV 0 0 27017 <REPLACED>.<REPLACED>.mongodb.net SRV 0 0 27017 <REPLACED>.<REPLACED>.mongodb.net HEX dump:
|
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
}
return d.DialContext(ctx, network, "8.8.8.8:53")
},
}
_, srvs, err := r.LookupSRV(context.Background(), service, "tcp", host) I have to point to Google DNS manually when using tethered hotspot sharing from iPhone (but Wi-Fi hotspot sharing works) |
Change https://go.dev/cl/540375 mentions this issue: |
As per RFC 3597: Receiving servers MUST decompress domain names in RRs of well-known type, and SHOULD also decompress RRs of type RP, AFSDB, RT, SIG, PX, NXT, NAPTR, and SRV (although the current specification of the SRV RR in RFC2782 prohibits compression, RFC2052 mandated it, and some servers following that earlier specification are still in use). This change allows SRV resource decompression. Updates golang/go#36718 Updates golang/go#37362 Change-Id: I473c0d3803758e5b12886f378d2ed54bd5392144 GitHub-Last-Rev: 88d2e06 GitHub-Pull-Request: #199 Reviewed-on: https://go-review.googlesource.com/c/net/+/540375 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com>
As of https://go.dev/cl/570156 this is now fixed. |
Does this issue reproduce with the latest release?
Yep.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat 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.Compiled on my MacBook Pro using different
go
versions, all the way togotip
versionCompiled using
GOOS=linux GOARCH=amd64 go build .
since I'm building for an Ubuntu 18.04 EC2 instance.I then
scp
ed 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
ssh
ing to the remote box I executed./mongoConnectTest -uri=mongodb+srv://$USER:$PASSWORD@$HOST/$TESTDB
and received the following error.
Notes
I'm using a DNS seedlist provided by an
SRV
record to access a cluster of machines exposing amongo
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 relevantDNS
records below.SRV record
TXT record
The text was updated successfully, but these errors were encountered: