Elusive bug -- ReplicaSetNoPrimary but only sometimes

I was on the M0 (shared, free) cluster, and very occasionally, I’d (seemingly randomly) get an error saying ServerSelectionError & ReplicaSetNoPrimary.

Here’s my setup:

  • My connection string is valid.
  • The network connection is stable.
  • retryWrites=true
  • w=majority
  • Allowed all IPs
  • All errors are caught.
  • I use the Mongo Node Driver version 5.7.0

But anyway, since I don’t know the exact cause of this problem, I thought it could be related to my M0 cluster, so I decided to upgrade to M10. The errors seem to be gone, but again I have no idea if it’ll appear again or what caused it. It’s a randomly appearing error.

If anyone has any insight, that would be very helpful.

Hey @Pyra_Metrik,

Welcome to the MongoDB Community!

There could be a few potential causes for the occasional ServerSelectionError/ReplicaSetNoPrimary such as connection pooling issues, or intermittent network outage.

However, feel free to reach out in case you face such an issue again.

Regards,
Kushagra

Hi @Kushagra_Kesav thanks for your answer.

Where can I read more about connection pooling issues? What exactly does that mean? And is it at all related to M0 cluster?

Hey @Pyra_Metrik,

Connection pooling is a technique used by database drivers and clients to maintain a cache/pool of open connections that can be reused, rather than opening and closing connections for every request. To read more about Connection Pool, please refer to the documentation.

Regards,
Kushagra

@Kushagra_Kesav

So it looks an instance of MongoClient (I’m using the node driver) manages its own connection pool to the MongoDB cluster.

So if the cluster is shared, I’m guessing there may be sometimes higher latency in establishing a connection? Would it be reasonable to assume that such a latency could cause the serverSelectionError/ReplicaSetNoPrimary errors?