0

I am using spring boot and spring data mongodb to connect to a remote mongodb instance hosted by mongodb. Recently, I started to see the following exception when starting up my app locally from my windows laptop (either from eclipse, gradlew bootRun, or heroku local):

... Caused by: com.mongodb.MongoConfigurationException: Failed looking up TXT record for host cluster0.baqtr.mongodb.net
... Caused by: java.io.UncheckedIOException: java.net.SocketException: Network is unreachable: connect

The format of my connection string is: mongodb+srv://${MONGODB_USER_NAME}:${MONGODB_PASSWORD}@cluster0.baqtr.mongodb.net/[db name]?retryWrites=true&w=majority

The connection is fine when my app is deployed in heroku, and I am also able to connect to the db from my laptop with mongosh using the same connection string.

The only thing I can think of that coincides with the appearance of this exception is the installation of certbot, which I have now uninstalled.

Adding some details: Running: dig TXT cluster0.baqtr.mongodb.net From the heroku instance: SERVER: 10.1.0.2#53(10.1.0.2) (UDP)

From a virtualbox instance running on my laptop: SERVER: 10.1.0.2#53(10.1.0.2) (UDP)

Directly from my laptop: SERVER: 8.8.8.8#53(8.8.8.8)

I currently have my preferred and alternate DNS servers set on the wifi network connection, ipv4 to 8.8.8.8 and 8.8.4.4 respectively (again, this is set through windows settings).

However, when I run ipconfig: Wireless LAN adapter Wi-Fi: Connection-specific DNS Suffix . : hsd1.ca.comcast.net

I also have been able to workaround the problem (so far) by setting a VM argument in my run configuration in eclipse: -Djava.naming.provider.url="dns://8.8.8.8"

I'm wondering if windows is overriding my manual dns config of 8.8.8.8 with the comcast dns, and the comcast dns is blocking my lookup of cluster0?

Pino
  • 7,468
  • 6
  • 50
  • 69
broadbear
  • 614
  • 8
  • 19
  • Following advice in the following answer fixed the issue for me: https://stackoverflow.com/a/76014810/1560534 The primary question I have now is why did it all of a sudden start happening? Could certbot have reconfigured something on my laptop? – broadbear Jul 26 '23 at 19:00
  • Additionally I was able to follow the instructions at the following link to solve the problem more generally. Basically I updated the preferred DNS server to 8.8.8.8 for my wifi adapter. https://www.zdnet.com/article/how-to-change-the-dns-settings-on-your-windows-pc/ – broadbear Jul 26 '23 at 19:14
  • Now its not working again. It just stopped working. I didn't change anything in a related area. I have now removed the settings on the wifi adapter, and I have attempted to add -Djava.naming.provider.url="dns://8.8.8.8" to the execution string, but neither works. – broadbear Jul 27 '23 at 00:07

1 Answers1

0

DNS records look healthy:

$ dig TXT cluster0.baqtr.mongodb.net

; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> TXT cluster0.baqtr.mongodb.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40273
;; flags: qr rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;cluster0.baqtr.mongodb.net.    IN      TXT

;; ANSWER SECTION:
cluster0.baqtr.mongodb.net. 0   IN      TXT     "authSource=admin&replicaSet=atlas-su9nnp-shard-0"

;; Query time: 19 msec
;; SERVER: 172.30.176.1#53(172.30.176.1) (UDP)
;; WHEN: Wed Jul 26 23:24:47 BST 2023
;; MSG SIZE  rcvd: 131



$ dig srv _mongodb._tcp.cluster0.baqtr.mongodb.net

; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> srv _mongodb._tcp.cluster0.baqtr.mongodb.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29292
;; flags: qr rd ad; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;_mongodb._tcp.cluster0.baqtr.mongodb.net. IN SRV

;; ANSWER SECTION:
_mongodb._tcp.cluster0.baqtr.mongodb.net. 0 IN SRV 0 0 27017 cluster0-shard-00-01.baqtr.mongodb.net.
_mongodb._tcp.cluster0.baqtr.mongodb.net. 0 IN SRV 0 0 27017 cluster0-shard-00-02.baqtr.mongodb.net.
_mongodb._tcp.cluster0.baqtr.mongodb.net. 0 IN SRV 0 0 27017 cluster0-shard-00-00.baqtr.mongodb.net.

;; Query time: 10 msec
;; SERVER: 172.30.176.1#53(172.30.176.1) (UDP)
;; WHEN: Wed Jul 26 23:25:38 BST 2023
;; MSG SIZE  rcvd: 272

It must be "Network is unreachable: connect" is failing to fetch these records from DNS server. Certbot or not, check DNS settings. It may try to connect to a local resolution service which you disabled, or a handful of other causes. The question doesn't have enough details, so any further assumptions would be pure speculation.

Alex Blex
  • 34,704
  • 7
  • 48
  • 75
  • Let me know any details that could help. I am working on a windows laptop from home over a Comcast XFinity cable modem. The block seems to be limited to a few things (I can set the google dns ip on the device and still access most of the internet; youtube, etc). Could the ISP be blocking my connection to cluster0 somehow? – broadbear Jul 27 '23 at 00:25
  • I believe "Failed looking up TXT record" means it's DNS being blocked, not cluster0. Please read the answer, repeat the same `dig` commands from your environment, compare the results, especially `;; SERVER:` part - it indicates which DNS server is being used to query TXT/SRV records. Get logs from your application - compare which DNS servers are being used from there and how they differ from system settings used in `dig` - it's a tracing and debugging job. You will need to have basic idea how DNS works or search for professional help to troubleshoot. – Alex Blex Jul 27 '23 at 09:28
  • Thanks for the responses. I've added some detail to the original post comparing outputs of running the dig command as well as ipconfig. I'm able to get my app running locally by adding -Djava.naming.provider.url="dns://8.8.8.8" to VM arguments in my eclipse run config (for now). I'm wondering I'm configuring windows properly to use 8.8.8.8 instead of the comcast dns. – broadbear Jul 27 '23 at 15:29