Getting ETIMEOUT error when attempting to connect

MongoDB Atlas was working fine at one time. Now I have not been able to connect for a time. I’ve looked at other solutions here on this forum as well as others including Stackoverflow.

I’m getting the aforementioned error using the application connection string, the MongoDB Compass app connection string as well as the MongoDB shell connection string.
Here are the things that I’ve tried:

  1. I have tried creating a new MongoDB Atlas account with a different cloud provider and region/zone.
  2. MongoDB Atlas has a connection rule in Windows Defender’s outbound rules. (Remote ports 27015-
    27017). I guess this was created by MongoDB during install, so the firewall should not be an issue.
  3. Whitelisted 0.0.0.0/0 ( a security risk, but there is no valuable data here).
  4. Started using a password that doesn’t require url encoding (no special characters).

Here is my software list:
nodejs: v16.13.0
express: v4.18.1
mongoose: v6.5.2

I’m placing my MongoDB Compass connection string here. I invite you to use it to try and connect. There is no sensitive data here so it’s not an issue to me…I just want to find out what preventing a connection.
I did read something about lowering the node version to fix it. If that’s the case, I’m willing to do that but what should it be lowered to?

We are planning a major rollout of a new application involving millions of potential hits per day, but if I can’t connect, I might as use another solution besides MongoDB.

MongoDB Compass connection string:
mongodb+srv://brohjoe1:password@cluster0.4ross7o.mongodb.net/auth (password masked…confirmed to be working by Yilmaz_Durmaz but I still can’t connect.

you may hide the connection string because it is working from my computer right now.

Since you say it was working before, I suspect your router/vpn/proxy restricts you for some reason, or your DNS settings have a problem and cannot resolve the name of the server.

I don’t think it is a Node.js or library version. Have you had any upgrades when this problem started?

By the way, it would be better to see the full error log. can you provide it?

In addition to my above post, do you try connecting from your home/work pc, or your app is on a cloud-hosted pc?
If you use a work network, it is possible the network admins have put some port restrictions on the network at that time. in that case, have you contacted them?
What else can you say about your project’s network structure?

by the way, on your connection string, add something like this: “confirmed to be working, masked the password”

I’m working from home using an Xfinity router. What do I need to do about the DNS settings? Here is the full errror log:

App is listening at http://localhost:3001
C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\connection.js:824
const serverSelectionError = new ServerSelectionError();
^

MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an
IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
at NativeConnection.Connection.openUri (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\connection.js:824:32)
at C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\index.js:380:10
at C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
at new Promise ()
at promiseOrCallback (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
at Mongoose._promiseOrCallback (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\index.js:1225:10)
at Mongoose.connect (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongoose\lib\index.js:379:20)
at Object. (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\app.js:11:10)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions…js (node:internal/modules/cjs/loader:1153:10) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(3) {
ac-v2tectr-shard-00-01.4ross7o.mongodb.net:27017’ => ServerDescription {
_hostAddress: HostAddress {
isIPv6: false,
host: ‘ac-v2tectr-shard-00-01.4ross7o.mongodb.net’,
port: 27017
},
address: ‘ac-v2tectr-shard-00-01.4ross7o.mongodb.net:27017’,
type: ‘Unknown’,
hosts: ,
passives: ,
arbiters: ,
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 1097611983,
lastWriteDate: 0,
error: MongoNetworkError: connect ETIMEDOUT 35.239.246.213:27017
at connectionFailureError (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongodb\lib\cmap\connect.js:379:20)
at TLSSocket. (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongodb\lib\cmap\connect.js:302:22)
at Object.onceWrapper (node:events:510:26)
at TLSSocket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
[Symbol(errorLabels)]: Set(0) {}
}
},
ac-v2tectr-shard-00-02.4ross7o.mongodb.net:27017’ => ServerDescription {
_hostAddress: HostAddress {
isIPv6: false,
host: ‘ac-v2tectr-shard-00-02.4ross7o.mongodb.net’,
port: 27017
},
address: ‘ac-v2tectr-shard-00-02.4ross7o.mongodb.net:27017’,
type: ‘Unknown’,
hosts: ,
passives: ,
arbiters: ,
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 1097611977,
lastWriteDate: 0,
error: MongoNetworkError: connect ETIMEDOUT 35.232.109.33:27017
at connectionFailureError (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongodb\lib\cmap\connect.js:379:20)
at TLSSocket. (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongodb\lib\cmap\connect.js:302:22)
at Object.onceWrapper (node:events:510:26)
at TLSSocket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
[Symbol(errorLabels)]: Set(0) {}
}
},
ac-v2tectr-shard-00-00.4ross7o.mongodb.net:27017’ => ServerDescription {
_hostAddress: HostAddress {
isIPv6: false,
host: ‘ac-v2tectr-shard-00-00.4ross7o.mongodb.net’,
port: 27017
},
address: ‘ac-v2tectr-shard-00-00.4ross7o.mongodb.net:27017’,
type: ‘Unknown’,
hosts: ,
passives: ,
arbiters: ,
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 1097612045,
lastWriteDate: 0,
error: MongoNetworkError: connect ETIMEDOUT 35.238.72.187:27017
at connectionFailureError (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongodb\lib\cmap\connect.js:379:20)
at TLSSocket. (C:\Users\brohj\WebstormProjects\Firebase\redEyeMedia\node_modules\mongodb\lib\cmap\connect.js:302:22)
at Object.onceWrapper (node:events:510:26)
at TLSSocket.emit (node:events:390:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
[Symbol(errorLabels)]: Set(0) {}
}
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: ‘atlas-bt7sor-shard-0’,
logicalSessionTimeoutMinutes: undefined
},
code: undefined
}

do you have any telnet program installed? I hope you do because the next commands will tell you if it is related to DNS or not, while also testing your connection to your cluster.

From your error log, the following address and IP are associated. telnet is used if the target MongoDB server can be connected. Check if you get any errors. an error from only first means a DNS problem. if both errors out that might be a bit complicated (or easy, couldn’t anticipate for now) as any broken firewall, antivirus program, router itself, network adapter settings can cause issues. (I keep nodejs and driver problems as the last scenario as your app was working)

telnet ac-v2tectr-shard-00-00.4ross7o.mongodb.net 27017
telnet 35.238.72.187 27017

If both connects, then first try these two directly to connect to this server of the cluster. and then try the same but by adding your username and password. if you fail, that might be a messy IP access list, so If you come to this step I would advise to clear and redefine all security setting.

mongo 35.238.72.187:27017
mongo ac-v2tectr-shard-00-00.4ross7o.mongodb.net:27017

please report your findings about these commands.

by the way, it is late night here. if no one else shows up to help further I will be back tomorrow.

I changed the DNS to Google’s IPv4 address: 8.8.8.8 and alternate 8.8.4.4. Still getting the same errors. I’m working your telnet solution next.

I used Putty to connect. Got timed out on both the host address and port and the IP address and port. By the way, I used Google’s DNS’s and my original settings (Obtain DNS server address automatically). I added Telnet to Windows programs and got ‘Could not open connection to the host, on port 27017: Connect failed.’ For the IP address, Windows telnet said, ‘Could not open connection to the host, on port 35.238.72.187 27017: Connect Failed.’

Could not sleep yet, so back here :slight_smile:

I have just noticed I took the IP address from your error log, which means your DNS is working correctly and associates your server address to its IP.

Then, the telnet giving a connection error eliminates the possibility of app and library problems. with putty, you should get either “connection closed” or window just closing without error. (set connection type to telnet, and “close window on exit” to “never” on the bottom).

Your firewall or virus protection may somehow have been set to block communication toward Atlas. Try disabling them for a while and test again.

Also, check if you have set some proxy or VPN and forgot you did so, and they might be blocking your access.

1 Like

there is plink.exe on putty’s page. you can have plink.exe -telnet ac-v2tectr-shard-00-00.4ross7o.mongodb.net -P 27017 -v command and the output should be the following (it will just exit proving connection):

Looking up host "ac-v2tectr-shard-00-00.4ross7o.mongodb.net" for Telnet connection
Connecting to 35.238.72.187 port 27017
client negotiation: WILL NAWS
client negotiation: WILL TSPEED
client negotiation: WILL TTYPE
client negotiation: WILL NEW_ENVIRON
client negotiation: DO ECHO
client negotiation: WILL SGA
client negotiation: DO SGA
Connected to 35.238.72.187

this log one is from my pc showing Atlas is fine along with my connection to it.

In your case, this should end with the following until you find the culprit:

Failed to connect to 35.238.72.187: Network error: Connection timed out
Network error: Connection timed out
FATAL ERROR: Network error: Connection timed out

I finally connected. I used my cell phone to tether to my computer and I was able to connect. That let me know that the problem was with my ISP. I have to ‘port forward’ port 27017 on my gateway. Thanks so much for helping me.

1 Like

I don’t know how your service provider or router works, but the connection towards Atlas should work without port forwarding, which you were already having some time ago.

It is good you have at least a connection now, but I recommend you investigate some more into the issue as you may experience worse problems in the future.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.