I have the issue. I've noticed this happens to applications with a
high writing rate. In other words, if your application is trying to make
too many write operations while the primary is down, it will eventually
throw the "connection closed" error.Kindly advice pls find the below connection string which i used mongodb://192.168.XX.XX:27017,192.168.XX.XX:27017,192.168.XX.XX:27017/?replicaSet=rs0 |
Hi Baskar
if your application is trying to make too many write operations while the primary is down, it will eventually throw the “connection closed” error.
This is by design, since there are many possible types of write operations (e.g. update whole documents, incrementing field, etc.) that could have different strategies on how to retry a write. If a failover happens while a write is ongoing, the driver does not retry the write by itself, since it could potentially create corrupt data if it choose the wrong retry strategy. Rather, the driver will throw an exception, letting the application know that an operation has failed due to network issues, try to reconnect to the replica set automatically, while leaving the retry strategy to the application.
In pymongo, there is an example on how to handle this exception in High Availability and PyMongo
For some background on why this approach is preferred, see:
Best regards,
Kevin