MongoDB Charts: DataSource connection timeout

523 views
Skip to first unread message

gu...@nucont.com

unread,
Nov 25, 2018, 8:31:21 PM11/25/18
to mongodb-user
I'm trying to add my first DataSource that is hosted on Compose.io.

The MongoDB URL it's correct, I could connect with MongoDB Compass with it. But at MongoDB Charts I receive this error:

error connecting to MongoDB: error connecting to MongoDB service cluster: server selection timeout

Anyone has any idea how to solve it?

Tom Hollander

unread,
Nov 26, 2018, 3:32:29 PM11/26/18
to mongodb-user
Hi -

This is a pretty generic error that means that the connection to MongoDB failed. If it works in Compass but fails in Charts it's probably down to one of two reasons:
  1. Charts runs within a Docker container, which can handle naming resolution differently to your host
  2. Charts uses the Go driver while Compass uses the Node driver, which can behave differently in very specific cases.
To help narrow this down, could you share the URI you are using, stripped of any sensitive information?
thanks
Tom

gu...@nucont.com

unread,
Nov 26, 2018, 3:43:04 PM11/26/18
to mongodb-user

gu...@nucont.com

unread,
Nov 26, 2018, 3:45:52 PM11/26/18
to mongodb-user
Just complementing:

Charts successfully connected to metadata DB, that it's in the same mongo deployment.

I can login, create dashboards and users normally. Just can't add a new datasource because of the timeout.


On Monday, November 26, 2018 at 6:32:29 PM UTC-2, Tom Hollander wrote:

gu...@nucont.com

unread,
Dec 5, 2018, 10:54:21 AM12/5/18
to mongodb-user
Any suggestion? 


On Monday, November 26, 2018 at 6:32:29 PM UTC-2, Tom Hollander wrote:

Robert Mühlbauer

unread,
Dec 6, 2018, 3:15:08 PM12/6/18
to mongodb-user
I think I've got a very similar, maybe even exactly the same problem: Google Groups - Unable to add Datasource

8020erwin

unread,
Dec 7, 2018, 7:06:57 AM12/7/18
to mongodb-user
Me too:
unable to connect data source
it is a database on mongodb.net M2

rkoc...@gmail.com

unread,
Dec 7, 2018, 5:18:14 PM12/7/18
to mongodb-user
Same problem here. We have exactly the same problem with MongoDB Charts described in post of Robert:



Hover Zhang

unread,
Jan 31, 2019, 6:13:16 PM1/31/19
to mongodb-user
I had the same problem.  Mongo compass is fine to connect, but mongo Charts cannot connect and get timeout error. 

mongodb://user:xxx@IP:27017/db?authSource=admin&authMechanism=SCRAM-SHA-1

Tom Hollander

unread,
Jan 31, 2019, 9:15:24 PM1/31/19
to mongodb-user
Hi Hover -

Sorry to hear you are having problems. The most likely causes for this are:
  • Network resolution/routing: the hostname you use needs to be resolvable and routable from the Charts Docker container. If you are connecting via IP this should work, but sometimes using hostnames this can be an issue depending on your network setup
  • Replica sets: If you are connecting to a replica set, you must specify the replicaSet parameter and the hostnames used in the replica set definition must be routable from the Charts container.
Also this probably isn't the issue, but you shouldn't need to specify SCRAM-SHA-1 in the URI as it should be implied.

Let me know if you make any progress or if you need any more ideas.

Tom

Hover Zhang

unread,
Jan 31, 2019, 9:25:30 PM1/31/19
to mongodb-user
Tom,

I did have replica set for 2 mongoDB. I only want to connect to slave mongoDB for mongo Charts. Are you trying to say I must connect using Replica sets even I only want to connect to one DB? Can I just connect to Slave MongoDB for Charts only?

I had replica set name: ARReplica0, the slave name: abc.domain.com. I can use IP for replica set. In this way, we do not need worry about hostname. However, it still fails. Below, I enable debug log for network, access control, tracking. It looks socket disconnected. The Charts server is 172.27.15.20 and it connect successfully to MongDB server, but it got disconnected immediately. See logs below.

Command on mongo charts data source connection:


2019-01-31T18:48:13.524-0600 D ASIO     [NetworkInterfaceASIO-Replication-0] Starting asynchronous command 2613 on host 172.27.15.79:27017
2019-01-31T18:48:13.525-0600 D ASIO     [NetworkInterfaceASIO-Replication-0] Request 2613 finished with response: { ok: 1.0, electionTime: ne                           w Date(6652427209292120065), state: 1, v: 7, hbmsg: "", set: "ARtestRS0", term: 3, primaryId: 0, durableOpTime: { ts: Timestamp 1548982086000                           |1, t: 3 }, opTime: { ts: Timestamp 1548982086000|1, t: 3 } }
2019-01-31T18:48:14.426-0600 I NETWORK  [thread1] connection accepted from 172.27.15.20:40650 #9 (5 connections now open)
2019-01-31T18:48:14.427-0600 D NETWORK  [conn9] Starting server-side compression negotiation
2019-01-31T18:48:14.427-0600 D NETWORK  [conn9] Socket recv() conn closed? 172.27.15.20:40650
2019-01-31T18:48:14.427-0600 D NETWORK  [conn9] SocketException: remote: 172.27.15.20:40650 error: 9001 socket exception [CLOSED] server [172                           .27.15.20:40650]
2019-01-31T18:48:14.427-0600 I -        [conn9] end connection 172.27.15.20:40650 (5 connections now open)
2019-01-31T18:48:15.525-0600 D ASIO     [ReplicationExecutor] startCommand: RemoteCommand 2615 -- target:172.27.15.79:27017 db:admin expDate:                           2019-01-31T18:48:25.525-0600 cmd:{ replSetHeartbeat: "ARtestRS0", configVersion: 7, from: "TXXXXXX::27017", fromId: 1, term:


Thanks.

Tom Hollander

unread,
Feb 3, 2019, 5:02:17 PM2/3/19
to mongodb-user
Hi Hover -

Unfortunately the method to connect to replica sets or single nodes varies a bit between MongoDB drivers. Charts uses the Go driver, which will always attempt to connect to the replica set by default, even if you don't specify the replicaSet parameter. If you don't want this, the solution is to specify connect=direct as a parameter to your URI, e.g.: mongodb://XXX:X...@172.22.15.141:27017/?connect=direct 

Please give that a go and let me know if it works.
Tom 
Reply all
Reply to author
Forward
0 new messages