Error connecting to :: caused by :: Connection refused

I am doing sharding with 1 config server, 1 shard and a mongos Instance.

I have setup the config server and shard as single member replica set and both are runnning on their IP with port 27019 and 27018 respectively. (I tested using telnet to check connectivity too)

I have my mongos.conf as follows

  destination: file
  path: /var/log/mongodb/mongos.log
  logAppend: true
  fork: true
  bindIp: router1
  configDB: test-configsrv-replica/cfg1:27019

And I have mapped cfg1 with IP address of config server and router1 as IP of mongos instance itself in /etc/hosts and I am strangely facing this issue while running mongos

{"t":{"$date":"2023-06-28T07:58:03.147+00:00"},"s":"I",  "c":"-",        "id":4333222, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"RSM received error response","attr":{"host":"","error":"HostUnreachable: Error connecting to :: caused by :: Connection refused","replicaSet":"test-configsrv-replica","response":{}}}
{"t":{"$date":"2023-06-28T07:58:03.147+00:00"},"s":"I",  "c":"NETWORK",  "id":4712102, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"Host failed in replica set","attr":{"replicaSet":"test-configsrv-replica","host":"","error":{"code":6,"codeName":"HostUnreachable","errmsg":"Error connecting to :: caused by :: Connection refused"},"action":{"dropConnections":true,"requestImmediateCheck":false,"outcome":{"host":"","success":false,"errorMessage":"HostUnreachable: Error connecting to :: caused by :: Connection refused"}}}}

I am not sure why this is trying to connect because in mongos it is cfg1 and its correctly mapped in hosts with Different IP Address

Any help would be appreciated! Thanks

You initialised the configserver replSet using as the hostname. The server discovery protocol uses the provided hostnames as seed and will query the replset for its members. Running db.hello() is basically the same thing a driver will do during this discovery.

Best to always use a hostname for the members and every host client/mongos/configSvr/shardSvr need to be able to resolve(and connect) those names.


Yes, that is correct. I was running configSrv with only localhost binding. Thanks @chris !