question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDB Connection Timeout

See original GitHub issue

Hello,

My setup: Dbeaver 4.1.1 EE (Windows 10) / MongoDB 3.2.12 on Ubuntu 16.04 under local Hyper-V Virtual Machine.

Lets start with what i get from dbeaver: 1)

Error connecting to Mongo instance [127.0.0.1]
  com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that 
matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is 
{type=REPLICA_SET, servers=[{address=wslu.sys:27017, type=UNKNOWN, state=CONNECTING, 
exception={com.mongodb.MongoSocketException: wslu.sys}, caused by 
{java.net.UnknownHostException: wslu.sys}}]

and

Error connecting to Mongo instance [192.168.1.2]
  com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that 
matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is 
{type=REPLICA_SET, servers=[{address=wslu.sys:27017, type=UNKNOWN, state=CONNECTING, 
exception={com.mongodb.MongoSocketException: wslu.sys}, caused by 
{java.net.UnknownHostException: wslu.sys}}]

Ad.1) Odd thing about this part is, i’m trying to connect here, to my mongodb using SSH tunnel, which is set to my local VM ip: 192.168.1.2 and mongo instance on that VM, also with IP 192.168.1.2. However in that error we can see both: 127.0.0.1 AND wslu.sys (vm hostname) - its odd. It should be 192.168.1.2 in both places, shouldn’t it?

Ad.2) This time, i’m trying to connect to my mongo instance DIRECTLY, so by using VM ip 192.168.1.2, but again, we can see here, that somehow its trying to connect to server wslu.sys.

Both, errors are popping up when i’m NOT filling Replica Set field in connection settings. But, when i do (in scenario without ssh tunnel):

Error connecting to Mongo instance [192.168.1.2]
  com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that 
matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is 
{type=REPLICA_SET, servers=[]

I really don’t get it. Any advice?

EDIT: My RS status output from mongo:

/* 1 */
{
    "set" : "rs",
    "date" : ISODate("2017-08-14T00:07:22.324Z"),
    "myState" : 1,
    "term" : NumberLong(68),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [ 
        {
            "_id" : 0,
            "name" : "wslu.sys:27017",
            "health" : 1.0,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 366700,
            "optime" : {
                "ts" : Timestamp(1502667624, 2),
                "t" : NumberLong(68)
            },
            "optimeDate" : ISODate("2017-08-13T23:40:24.000Z"),
            "electionTime" : Timestamp(1502302543, 1),
            "electionDate" : ISODate("2017-08-09T18:15:43.000Z"),
            "configVersion" : 1,
            "self" : true
        }
    ],
    "ok" : 1.0
}

Btw. RoboMongo connects without issues.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
serge-ridercommented, Dec 2, 2017

Extra driver property was added. It may help in case of SSH tunnel and replica sets. You could try it in version 4.3:

image

0reactions
serge-ridercommented, Jun 7, 2018

I can’t say because I can’t reproduce this. And I don’t fully understand the nature of this problem.

Did you try to use some 3rd party SSH client (e.g. Putty) for SSH tunnel? (https://blockdev.io/connecting-to-a-mongo-replica-set-via-ssh/)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect timeout and execution timeout in nodejs driver
The connectTimeoutMS option is used by the driver to determine when to timeout an attempt to connect an individual connection to a server...
Read more >
mongodb connection timed out error - Stack Overflow
For anyone looking to set the initial database connection timeout, you can do so via serverSelectionTimeoutMS . Currently this option is not ...
Read more >
Understanding MongoDB Client Timeout Options - ScaleGrid
Connection timeout is the number of milliseconds the driver will wait before a new connection attempt is aborted. After selection of the server, ......
Read more >
URI Connection Settings - GitHub Pages
Option Affects Type Default poolSize Server, ReplicaSet, Mongos integer 5 ssl Server, ReplicaSet, Mongos boolean false sslValidate Server, ReplicaSet, Mongos boolean false
Read more >
MongoDB "Connection Timed Out" Error on CCO - Cisco
After you configure the MongoDB for CCO, it fails to connect to MongoDB due to the connection timeout error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found