[COMPASS-4534] Unable to connect with v1.24.1 - Error: getaddrinfo ENOTFOUND mongodb Created: 10/Dec/20  Updated: 29/Oct/23  Resolved: 17/Dec/20

Status: Closed
Project: Compass
Component/s: Compass
Affects Version/s: 1.24.1
Fix Version/s: 1.24.6

Type: Bug Priority: Critical - P2
Reporter: Lester Waters Assignee: Rhys Howell
Resolution: Fixed Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 Desktop


Attachments: PNG File Compass_ENOTFOUND.png     PNG File image-2020-12-10-11-48-06-545.png     PNG File image-2020-12-10-11-48-21-028.png    
Issue Links:
Depends
Related
is related to COMPASS-4536 Can't connect using username/password Closed
Documentation Changes: Not Needed
Sprint: Iteration Star Apple

 Description   

Problem Description

I am no longer able to connect to MongoDB using *Compass 1.24.1*.
I am able to connect using Compass 1.23.0.

In v1.24.1, connections fail with a getaddrinfo ENOTFOUND mongodb error.
Connecting with any other application such as a 3rd party app (NoSQLBooster) works fine.
See the screenshot below:

 

I tested this on a second machine where I still had v1.23.0 installed.  The connection worked prior to upgrading to v1.24.1. It immediately stopped working after the upgrade. See screenshot, which shows before and after:

Steps to Reproduce

(1) Create a single node MongoDB Community Instance on a LAN

(2) Use the connection string to connect.

Expected Results

Successful connection.

Actual Results

Error: getaddrinfo ENOTFOUND mongodb

Observations

When I enter a connection string into *Compass v1.24.1* such as:

mongodb://user:XXXXX@HOSTNAME.com:27017/ops?authSource=admin

Compass expands the connection string with default values to become:

mongodb://user:XXXXX@HOSTNAME.com:27017/ops?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false

This expansion happens in both 1.24.1 and 1.23.0 but the connection only fails in v1.24.1. It works fine in v1.23.0. If I use the first connection string in a different app such as NoSQLBooster, the connection works fine. But if I use the altered connection string in that app with &readPreference=primary, it fails with the same error that Compass fails with. I only provide this detail as a trace from NoSQLBooster as it might shed light on the Compass issue.

The issue appears that the fully expanded connection string is being passed to the server. I'm not sure why this fails when the parameter is added. I can only speculate that the MongoDB server instance (in this case, community edition used for testing), is rejecting the connection due to the presence of the string. 

TEST 1 (Failure)

This shows the FAILED connection with the exact same error that Compass returns using the connection string:
mongodb://user:XXXXX@HOSTNAME.com:27017/ops?authSource=admin&readPreference=primary

Although this is a trace from a different application, it may shed light on the issue with Compass.

Version: 6.2.4OS: {"platform":"win32","type":"Windows_NT","release":"10.0.19042","mem":"32G"}Brief:
Connect to HOSTNAME.com Status:Failed Duration:Error:
MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [Error: getaddrinfo ENOTFOUND mongodbDetails:
10:34:57.766 *** Starting "Discover Replica Set" to get rs name***10:34:57.994 *** Finished "Discover Replica Set" 228 ms ***
{{

{"hosts":[\{"host":"mongodb","port":27017,"role":"primary"}

],"setName":"rs0"}}}10:34:57.995 *** Starting MongoClient.connect ***
{{

{"options":\{"appname":"NoSQLBoosterV6.2.4_94929.153","autoReconnect":true,"keepAlive":60000,"minSize":1,"poolSize":1,"promoteLongs":false,"promoteValues":false,"reconnectTries":172800,"sslValidate":false,"useNewUrlParser":true,"useUnifiedTopology":false}

,"uri":"mongodb://user:******@HOSTNAME.com:27017/ops?authSource=admin&readPreference=primary&replicaSet=rs0"}}}10:34:57.998 Topology Opening
{{

{"topologyId":5}

}}10:34:58.007 Server Opening
{{

{"address":"HOSTNAME.com:27017","topologyId":5}

}}10:34:58.097 Server Description Changed
{{

{"address":"HOSTNAME.com:27017","newDescription":\{"address":"HOSTNAME.com:27017","arbiters":[],"hosts":[],"passives":[],"type":"RSPrimary"}

,"previousDescription":{"address":"HOSTNAME.com:27017","arbiters":[],"hosts":[],"passives":[],"type":"Unknown"}}}}10:34:58.097 Server Closed
{{

{"address":"HOSTNAME.com:27017","topologyId":5}

}}10:34:58.103 Server Opening
{{

{"address":"mongodb:27017","topologyId":5}

}}10:35:00.379 Topology Description Changed
{{

{"diff":\{"servers":[]}

,"newDescription":{"servers":[],"setName":"rs0","topologyType":"Unknown"},"previousDescription":{"servers":[],"topologyType":"Unknown"},"topologyId":5}}}10:35:00.379 Server Closed
{{

{"address":"mongodb:27017","topologyId":5}

}}10:35:00.379 Topology Closed
{{

{"topologyId":5}

}}10:35:00.380 Topology Description Changed
{{

{"diff":\{"servers":[]}

,"newDescription":{"servers":[],"setName":"rs0","topologyType":"Unknown"},"previousDescription":{"servers":[],"setName":"rs0","topologyType":"Unknown"},"topologyId":5}}}10:35:00.380 Topology Closed
{{

{"topologyId":5}

}}10:35:00.380 *** Connect Error ***
{{

{"message":"failed to connect to server [mongodb:27017] on first connect [Error: getaddrinfo ENOTFOUND mongodb\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) \{\n name: 'MongoNetworkError'\n}

]","name":"MongoNetworkError","stack":"MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [Error: getaddrinfo ENOTFOUND mongodb\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {\n name: 'MongoNetworkError'\n}]\n at Pool.<anonymous> (C:\\Users\\LesterWaters\\AppData\\Local\\Programs\\nosqlbooster4mongo\\resources\\app.asar\\node_modules\\mongodb\\lib\\core\\topologies\\server.js:438:11)\n at Pool.emit (events.js:203:13)\n at C:\\Users\\LesterWaters\\AppData\\Local\\Programs\\nosqlbooster4mongo\\resources\\app.asar\\node_modules\\mongodb\\lib\\core\\connection\\pool.js:562:14\n at C:\\Users\\LesterWaters\\AppData\\Local\\Programs\\nosqlbooster4mongo\\resources\\app.asar\\node_modules\\mongodb\\lib\\core\\connection\\pool.js:1009:9\n at C:\\Users\\LesterWaters\\AppData\\Local\\Programs\\nosqlbooster4mongo\\resources\\app.asar\\node_modules\\mongodb\\lib\\core\\connection\\connect.js:32:7\n at callback (C:\\Users\\LesterWaters\\AppData\\Local\\Programs\\nosqlbooster4mongo\\resources\\app.asar\\node_modules\\mongodb\\lib\\core\\connection\\connect.js:280:5)\n at Socket.<anonymous> (C:\\Users\\LesterWaters\\AppData\\Local\\Programs\\nosqlbooster4mongo\\resources\\app.asar\\node_modules\\mongodb\\lib\\core\\connection\\connect.js:310:7)\n at Object.onceWrapper (events.js:291:20)\n at Socket.emit (events.js:203:13)\n at emitErrorNT (internal/streams/destroy.js:91:8)\n at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)\n at processTicksAndRejections (internal/process/task_queues.js:77:11)"} }}

TEST 2 (Success)

This shows a successful connection where *readPreference=* is omitted from the connection string.

mongodb://user:XXXXX@HOSTNAME.com:27017/ops?authSource=admin

10:36:40.842 *** Starting MongoClient.connect ***
{"options":\{"appname":"NoSQLBoosterV6.2.4_94929.153","autoReconnect":true,"keepAlive":60000,"minSize":1,"poolSize":1,"promoteLongs":false,"promoteValues":false,"reconnectTries":172800,"sslValidate":false,"useNewUrlParser":true,"useUnifiedTopology":false},"uri":"mongodb://user:******@HOSTNAME.com:27017/ops?authSource=admin"}10:36:40.949 Topology Opening
{"topologyId":23}10:36:40.949 Server Opening
{"address":"HOSTNAME.com:27017","topologyId":23}10:36:40.949 Server Description Changed
{"address":"HOSTNAME.com:27017","newDescription":\{"address":"HOSTNAME.com:27017","arbiters":[],"hosts":[],"passives":[],"type":"RSPrimary"},"previousDescription":{"address":"HOSTNAME.com:27017","arbiters":[],"hosts":[],"passives":[],"type":"Unknown"}}10:36:40.949 Topology Description Changed
{"address":"HOSTNAME.com:27017","newDescription":{"servers":[{"address":"HOSTNAME.com:27017","arbiters":[],"hosts":[],"passives":[],"type":"RSPrimary"}],"topologyType":"Single"},"previousDescription":{"servers":[{"address":"HOSTNAME.com:27017","arbiters":[],"hosts":[],"passives":[],"type":"Unknown"}],"topologyType":"Unknown"}}10:36:40.949 *** Finished MongoClient.connect 108 ms ***
{"options":\{"appname":"NoSQLBoosterV6.2.4_94929.153","autoReconnect":true,"keepAlive":60000,"minSize":1,"poolSize":1,"promoteLongs":false,"promoteValues":false,"reconnectTries":172800,"sslValidate":false,"useNewUrlParser":true,"useUnifiedTopology":false},"uri":"mongodb://user:*****@HOSTNAME.com:27017/ops?authSource=admin"}10:36:40.950 *** Starting Detecting MongoDB Server BuildInfo ***10:36:40.953 *** Finished Detecting MongoDB Server BuildInfo 3 ms**
}}{{10:36:40.953 Server Closed
{"address":"HOSTNAME.com:27017","topologyId":23}
10:36:40.954 Topology Closed
{{{"topologyId":23} }}

 

 

 

 



 Comments   
Comment by Githook User [ 16/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix(connectivity): use older driver defaults for directConnection and readPreference COMPASS-4539 COMPASS-4534 (#2083)
Branch: 1.24-releases
https://github.com/mongodb-js/compass/commit/6f49eac32021f83d66377a0a22e4b927a0a0fb96

Comment by Githook User [ 16/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: Revert "fix(connection-model): directConnection and readPreference connectivity fix COMPASS-4539 COMPASS-4534 (#2078)" (#2082)

This reverts commit b10a3dfd11f4d0e873db11db915ffa6950a75ab0.
Branch: 1.24-releases
https://github.com/mongodb-js/compass/commit/bc494df4301eea1c75248578c3fb2113a6a3e6dc

Comment by Githook User [ 16/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix(connectivity): use older driver defaults for directConnection and readPreference COMPASS-4539 COMPASS-4534 (#2083)
Branch: master
https://github.com/mongodb-js/compass/commit/6f49eac32021f83d66377a0a22e4b927a0a0fb96

Comment by Githook User [ 16/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: Revert "fix(connection-model): directConnection and readPreference connectivity fix COMPASS-4539 COMPASS-4534 (#2078)" (#2082)

This reverts commit b10a3dfd11f4d0e873db11db915ffa6950a75ab0.
Branch: master
https://github.com/mongodb-js/compass/commit/bc494df4301eea1c75248578c3fb2113a6a3e6dc

Comment by Githook User [ 16/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: Revert "fix(connection-model): directConnection and readPreference connectivity fix COMPASS-4539 COMPASS-4534 (#2078)"

This reverts commit b10a3dfd11f4d0e873db11db915ffa6950a75ab0.
Branch: revert-2078-bump-connection-model-and-dataservice-for-direct-connection-fix
https://github.com/mongodb-js/compass/commit/587718abb77d6082758dcfac8ad94aa46cfb041b

Comment by Alex Richards [ 15/Dec/20 ]

I also experienced this problem but the error message I had was connection timeout. This was when trying to use an SSL tunnel to connect to my MongoDB instance.

Resolved the issue by rolling back from 1.24 > 1.23

Comment by Githook User [ 15/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix(connection-model): directConnection and readPreference connectivity fix COMPASS-4539 COMPASS-4534 (#2078)
Branch: 1.24-releases
https://github.com/mongodb-js/compass/commit/b10a3dfd11f4d0e873db11db915ffa6950a75ab0

Comment by Githook User [ 15/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix(connection-model): directConnection and readPreference connectivity fix COMPASS-4539 COMPASS-4534 (#2078)
Branch: master
https://github.com/mongodb-js/compass/commit/b10a3dfd11f4d0e873db11db915ffa6950a75ab0

Comment by Githook User [ 14/Dec/20 ]

Author:

{'name': 'Rhys', 'email': 'Anemy@users.noreply.github.com', 'username': 'Anemy'}

Message: fix: set directConnection true on direct connections COMPASS-4534 (#337)
Branch: master
https://github.com/mongodb-js/connection-model/commit/bbb576b6253e48ef245e0678e030ae1b8874f35a

Comment by Massimiliano Marcon [ 14/Dec/20 ]

Thank you for the detailed bug report. We are investigating the problem and hopefully we'll have a fix or a workaround soon.

Comment by Ran Schindler [ 13/Dec/20 ]

I have the same issue while trying to connect to a mongo instance through a tunnel

Could it be that while creating new connection on Mongo Compass 1.24.1 the UI try to discover the entire replica set topology and connect to the primary/secondary IP.

Is there a way to create a DIRECT connection to an HOST/IP+Port just like the clients api and disable the topology discovery step?

From pymongo documentation: directConnection (optional): if True, forces this client to connect directly to the specified MongoDB host as a standalone . If false, the client connects to the entire replica set of which the given MongoDB host(s) is a part

Comment by Lester Waters [ 13/Dec/20 ]

Curious. In this case, there is no replica set configured (single node instance used for testing).  Why would it work with v1.23.0 and not with v1.24.0? This is readily reproducable on multiple VMs with the exact same connection string on multiple VMs. I can connect with v1.23.0 and as soon as I upgrade, I cannot connect.  If I uninstall v1.24.1 and reinstall v1.23.0, it starts working again. 

 

Comment by Alex Kubacki [ 12/Dec/20 ]

I can only speculate that the MongoDB server instance (in this case, community edition used for testing), is rejecting the connection due to the presence of the string. 

 I don't believe this is the case. From my tests with 1.24.1 (as compared to 1.23.0) what I see is:

  • Compass connects to the hostname I provide, and actually reaches Mongo
  • Compass runs `isMaster` or something and pulls the hostname of the current master node from the replicaset configuration
  •  Compass tries to reconnect to the master node hostname that it discovered

In your case, it looks like you're connecting to a (redacted) "HOSTNAME.com:27017", and your replica set configuration has the node address of "mongodb:27017". Hence, your error:

MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [Error: getaddrinfo ENOTFOUND]

I don't know yet how to work around this, other than to use split-horizon DNS in my case, so if there's a at least a connection parameter to connect in a "single node" manner rather than attempt to connect to the replicaset, I would greatly appreciate knowing about it.

Generated at Wed Feb 07 22:36:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.