Pymongo not automatically connecting to new primary

185 views
Skip to first unread message

Gabe Rives-Corbett

unread,
Oct 20, 2016, 3:32:08 PM10/20/16
to mongodb-user
Hello,

I'm using pymongo/flask with a connection string like this: "mongodb://mongo-1,mongo-2,mongo-3/untapt?replicaSet=myreplicaset".

It all works fine on the initial connection.  If we kill the primary, we see the cluster elect a new one, the pymongo request fails with an AutoReconnect error, but it does not appear to attempt to reconnect to the new primary.  With PyMongo 2.x we get the error: "AutoReconnect: No replica set primary available for query with ReadPreference PRIMARY"

With 3.x the initial connection does not work at all and we get: "ServerSelectionTimeoutError: No replica set members found yet"

Any help would be appreciated.

Bernie Hackett

unread,
Oct 21, 2016, 7:04:20 PM10/21/16
to mongodb-user
I'm going to guess either your application uses the multiprocessing module to fork subprocesses or your web framework does. Either way, read this:


With the related in-depth technical explanation:

Reply all
Reply to author
Forward
0 new messages