AutoReconnect: There are no replica set items for the query with ReadPreference PRIMARY_PREFERRED

Question What is the best way to deal with this error? Try again, say, 30 seconds for max. 5 times?

Settings I have PRIMARY + two SECONDARY settings on AWS ECS, and none of them have been disabled.

From the exception message, it seems that Mongo says: “I have NO BASE, and I tried to get data from SECONDARY, but they are too much.” But none of the Mongo servers were shut down. I had another process that has read_preference by default SECONDARY and works 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 

MongoDB Version : 2.2.0 and PyMongo: 2.4.2

+4
source share
3 answers

check socketTimeoutMS and socketTimeoutMS . Maybe this is very small?

+2
source

I would double check your replica configuration. Run rs.status() on one of your replica set members and make sure that the name field for each item is actually correct and resolved from the computer on which your application is running.

+8
source

I also had problems with this problem.

  • Run rs.status() and mark the machine name in the syncingTo field.
  • Change /etc/hosts to add this machine name with an IP address.
  • Repeat the script.

Mongo documentation on configuring /etc/hosts found here .

+2
source

Source: https://habr.com/ru/post/1484237/


All Articles