Reputation: 8790
Question What's the best way to handle this kind of error? Retries after say, 30 seconds for a max. of 5 times?
Setup I have a PRIMARY + two SECONDARY setup on AWS ECS and none of the boxes have been down.
From the exception message, it seems like Mongo is saying "I don't have PRIMARY and I tried to get you data from SECONDARY but they're down too". But, none of the Mongo servers were down. I had another process running which has a default read_preference
of SECONDARY
and that has been running fine.
Exception
is_auth = db.authenticate("myid","mypass")
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
720, in authenticate
read_preference=read_pref)["nonce"]
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
390, in command
result = self["$cmd"].find_one(command, **extra_opts)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py",
line 598, in find_one
for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
814, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
763, in _refresh
self.__uuid_subtype))
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
700, in __send_message
**kwargs)
File
"/usr/local/lib/python2.7/dist-packages/pymongo/mongo_replica_set_client.py
", line 1210, in _send_message_with_response
raise AutoReconnect(msg, errors)
AutoReconnect: No replica set members available for query with
ReadPreference PRIMARY_PREFERRED
Code
connection = MongoReplicaSetClient(, replicaSet='myReplica-2', use_greenlets = True)
db = "my_real_db"
db.read_preference = ReadPreference.PRIMARY
is_auth = db.authenticate("myid", "mypass") # ERROR at this line
Versions MongoDB: 2.2.0 and PyMongo: 2.4.2
Upvotes: 4
Views: 7170
Reputation: 191
I also had problems with this issue.
rs.status()
and note the machine name of the "syncingTo" field./etc/hosts
by adding that machine name with IP.Mongo documentation on configuring /etc/hosts
found here.
Upvotes: 2
Reputation:
I would double check your replica set configuration. Run rs.status()
on one of your replica set members and make sure that the 'name' field for each member is in fact correct and resolves from the machine your application is running on.
Upvotes: 8
Reputation: 3448
check your connectTimeoutMS
and socketTimeoutMS
. May be, it's very small?
Upvotes: 3