Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-918

Auth err from resyncing member prevents primary discovery

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.8.1
    • Affects Version/s: 2.6.3
    • Component/s: None
    • None

      If you use a MongoReplicaSetClient instead of a MongoClient in the same circumstances as in PYTHON-917, the RS client's monitor thread doesn't catch the auth failure and dies. Combine the mock server code from PYTHON-917 with this client code, using PyMongo 2.6.3:

      import traceback
      from time import sleep
      
      from pymongo import MongoReplicaSetClient
      
      client = MongoReplicaSetClient('localhost:2000,localhost:2001', replicaSet='rs')
      client.db.authenticate('user', 'password')
      
      for _ in range(15):
          try:
              print client.db.collection.find_one()
          except:
              traceback.print_exc()
              sleep(0.5)
      

      ... throws continuously:

      Traceback (most recent call last):
        File "/Users/emptysquare/.virtualenvs/mockup/mongo-mockup-db/CS-20300-client.py", line 11, in <module>
          print client.db.collection.find_one()
        File "pymongo/collection.py", line 604, in find_one
          for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
        File "pymongo/cursor.py", line 904, in next
          if len(self.__data) or self._refresh():
        File "pymongo/cursor.py", line 848, in _refresh
          self.__uuid_subtype))
        File "pymongo/cursor.py", line 782, in __send_message
          res = client._send_message_with_response(message, **kwargs)
        File "pymongo/mongo_replica_set_client.py", line 1537, in _send_message_with_response
          self.__schedule_refresh(sync=sync)
        File "pymongo/mongo_replica_set_client.py", line 1077, in __schedule_refresh
          self.__monitor.schedule_refresh()
        File "pymongo/mongo_replica_set_client.py", line 295, in schedule_refresh
          "Monitor thread is dead: Perhaps started before a fork?")
      InvalidOperation: Monitor thread is dead: Perhaps started before a fork?
      

      Again, the bug is that in PyMongo 2 we attempt authentication with monitoring sockets, whereas in PyMongo 3, monitoring sockets are unauthenticated. Furthermore, PyMongo 3's monitor threads catch all exceptions, but PyMongo 2's catch only network errors.

      The PyMongo 2 monitor can be made more robust if MongoReplicaSetClient catches both AutoReconnect and OperationFailure in MongoReplicaSetClient.refresh, in both the except-statements in that method. But, as in PYTHON-917, I'm concerned about breaking compatibility in the common case in exchange for fixing a very rare bug in the now-obsolete PyMongo 2 code.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: