Server selection error: server selection timeout, current topology

I’m trying to connect to via my code in golang. I am using the mongo-driver module. I am able to connect to instance:

mongodb+srv://<username>:<password>@cluster0-0pjmx.mongodb.net/test?retryWrites=true&w=majority

But on this line:

insertResult, err := collection.InsertOne(context.TODO(), entry_one)

I get this panic:

2020/04/18 15:56:55 server selection error: server selection timeout, current topology: { Type: Repl
icaSetNoPrimary, Servers: [{ Addr: cluster0-shard-00-00-0pjmx.mongodb.net:27017, Type: Unknown, Stat
e: Connected, Average RTT: 0, Last error: connection() : connection(cluster0-shard-00-00-0pjmx.mongo
db.net:27017[-179]) incomplete read of message header: EOF }, { Addr: cluster0-shard-00-01-0pjmx.mon
godb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : connecti
on(cluster0-shard-00-01-0pjmx.mongodb.net:27017[-181]) incomplete read of message header: EOF }, { A
ddr: cluster0-shard-00-02-0pjmx.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0,
Last error: connection() : connection(cluster0-shard-00-02-0pjmx.mongodb.net:27017[-180]) incomplete
read of message header: read tcp 192.168.43.131:34958->3.7.51.68:27017: read: connection reset by p
eer }, ] }
exit status 1

Any idea if I am missing something?

Hi @sntsh, welcome!

You’re getting the error message on insert operation because the database deployment has been identified as a replica set without a primary. Check whether your MongoDB Atlas cluster has any alerts. See also Replica set has no primary alert.

Regards,
Wan.

4 Likes

Thanks very much.

I don’t see any cluster alerts.

Aren’t there any step by step solution for this?

1 Like

I’m not 100% sure, but these seem like SSL errors. Unfortunately, those manifest as vague errors like “EOF” because the server closes the connection if the driver isn’t configured to connect with correct SSL settings. A few questions to dig deeper into this:

  1. Is this an Atlas cluster?
  2. Do you have access to the server logs? Those would confirm/deny my guess about this being an SSL issue.
  3. Is this application running on your local computer or a Docker container / VM / k8s / etc?
1 Like

Hello @sntshk I have same problem.
Did you find solution?

Ok. I found solution for my case. I added IP into whitelist and now it’s working.

17 Likes

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