[GODRIVER-829] Go 1.11 LookupSRV cannot unmarshal DNS message Created: 13/Feb/19  Updated: 27/Oct/23  Resolved: 11/Apr/19

Status: Closed
Project: Go Driver
Component/s: Connections
Affects Version/s: 0.3.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Wan Bachtiar Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

go1.11.5
go1.10.8


Attachments: HTML File Dockerfile    
Issue Links:
Duplicate
is duplicated by GODRIVER-879 Not able to connect to MongoDB Atlas ... Closed
is duplicated by GODRIVER-1027 Unable to connect to mongodb from gol... Closed
Related
is related to GODRIVER-875 The golang driver is not able to pars... Closed

 Description   

Connecting to MongoDB using connection URI SRV in Go v1.11 generates an error: cannot unmarshal DNS message.

The following code works in Go v1.10 but not in Go v1.11:

        mongoURI := "mongodb+srv://USER:PWD@ts-cluster-ci22a.mongodb.net/test?ssl=true&retryWrites=true"
        client, err := mongo.NewClient(mongoURI)
        if err != nil {
                log.Fatal(err)
        }
        err = client.Connect(context.TODO())
        if err != nil {
                log.Fatal(err)
        }

Also, the same code above works with non-SRV URI in Go v1.11.

This looks to be related to the change in the net package: https://github.com/golang/go/issues/10622

The call below would work in Go v1.10 but failed in Go v1.11:

        _, _, err := net.LookupSRV("mongodb", "tcp", "ts-cluster-ci22a.mongodb.net")
        if err != nil {
            log.Fatal(err)
        }



 Comments   
Comment by Bagus Prasetyo [ 17/Jun/20 ]

I still get same problem :

code :

client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb+srv://username:password@h.gcp.mongodb.net/database?retryWrites=true&w=majority"))

return :

panic: error parsing uri: lookup h.gcp.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message
goroutine 1 [running]:
main.init.0()

 

Specs:

[Fido2] $ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.3 LTS"
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
 
[Fido2] $ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 template# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
 
[Fido2] $ cat go.mod | grep mongo
        go.mongodb.org/mongo-driver v1.3.4

 

Comment by Syed Gillani [ 29/Mar/19 ]

Hi Wan,

According to my understanding, the docker container copies the DNS properties from the host on startup. However, it was not the case and I had to manually set the DNS while running the container. Thanks for looking into it and it worked with the proposed changes. 

I believe that there should be a fix of it at client level.

 

Syed 

Comment by Wan Bachtiar [ 29/Mar/19 ]

Hi syd,

The `/etc/resolv.conf` that you posted is from your macOS (the Docker host). What you need to update is the `/etc/resolv.conf` within your Docker container that runs your Go application.

Comment by Syed Gillani [ 28/Mar/19 ]

Hi Jeff, 

Following is the content of my `/etc/resolv.conf` file:

 

#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 1.1.1.1
nameserver 1.0.0.1
nameserver 192.168.1.1

Comment by Jeffrey Yemin [ 27/Mar/19 ]

That does look like the same error.  What DNS server do you have configured in /etc/resolv.conf?

Comment by Syed Gillani [ 27/Mar/19 ]

Hi Jeff, 

 

Following is the error after the docker build:

 error parsing uri (mongodb+srv://XXX:XXX@cluster4-XXX.mongodb.net/test?ssl=true&retryWrites=true): lookup cluster0-vlmfk.mongodb.net on 192.168.65.1:54: cannot unmarshal DNS message

 

 

Comment by Jeffrey Yemin [ 27/Mar/19 ]

Hi Syed,

Please post the specific error message you're seeing. It must be a different issue that you're encountering, or else you're doing something subtly different than wan.bachtiar.

Comment by Syed Gillani [ 27/Mar/19 ]

Hi Jeff, I've already tried the suggested workaround  from Wan but It didn't resolve my issue.

 

 

Comment by Jeffrey Yemin [ 26/Mar/19 ]

syd, please see wan.bachtiar's comment from March 15 on this issue. He provides a workaround to the problem.

Comment by Syed Gillani [ 26/Mar/19 ]

Is there any update on this issue? I'm having the same issue with the docker!!

 

Comment by ollevche [ 15/Mar/19 ]

No, im not using docker. It's ubuntu installed on my machine. Have fixed by replacing DNS server. Thank you!

Comment by Wan Bachtiar [ 15/Mar/19 ]

I could reproduce this in Docker with Ubuntu 18.04 instance, but not in macOS.
ollevche Are you also encountering this issue on Docker ?

To reproduce this, I have attached a Dockerfile for the code snippet above. Dockerfile

After looking into my issue further, it seems to be a combination of two things. The first one being the Docker DNS server and the second one being the change of SRV resolver in go1.11 (So I think is no longer relevant for this issue to be in MongoDB Go driver).

The solution is to replace the `nameserver` in `/etc/resolv.conf` to a public DNS server i.e. `1.1.1.1` or `8.8.8.8`.

Comment by ollevche [ 14/Mar/19 ]

What do you think it is fixed in Go 1.12? I can test in ~20 hours and post the results

Comment by Jeffrey Yemin [ 14/Mar/19 ]

Looking for Go platform-related issues, and found: https://github.com/golang/go/issues/27546.

Comment by ollevche [ 14/Mar/19 ]

I have faced it with Go v1.11.5 but haven't tried with Go v1.10

Comment by Jeffrey Yemin [ 14/Mar/19 ]

Hi ollevche,

Can you also not reproduce this using Go v1.10?

Comment by ollevche [ 14/Mar/19 ]

I'm on ubuntu 18.04
How can i help?

Comment by Jeffrey Yemin [ 14/Mar/19 ]

Hi wan.bachtiar, can you help us to reproduce this? We were unable to do so on on OS X Mojave.

Comment by ollevche [ 14/Mar/19 ]

Had the same issue with the latest driver version (1.0.0) and Go 1.11.5. Can we hope for a fix?

Comment by Isabella Siu (Inactive) [ 22/Feb/19 ]

Hi wan.bachtiar,

I tried these with Go 1.11.5 and the most recent version of the driver, and I wasn't able to get them to reproduce. Is this still a problem?

Generated at Thu Feb 08 08:35:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.