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

In test_retryable_writes every insert operation creates a new connection when retryWrites is enabled

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Every retryable insert command fails on the first attempt with a connection error. For example:

          def test_retryable_writes_does_not_retry_without_cause(self):
              listener = OvertCommandListener()
              client = rs_or_single_client(
                  retryWrites=True, event_listeners=[listener])
              client.testdb.testcoll.insert_one({})
              client.testdb.testcoll.update_one({}, {'$set': {'a': 1}})
              client.testdb.testcoll.find_one_and_update({}, {'$set': {'a': 1}})
              client.testdb.testcoll.insert_many([{}, {}])
              self.assertFalse(listener.results['failed'])
      

      The above test fails with this error:

        File "/Users/shane/git/mongo-python-driver/test/test_retryable_writes.py", line 464, in test_retryable_writes_does_not_retry_without_cause
          self.assertFalse(listener.results['failed'])
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/unittest/case.py", line 759, in assertFalse
          raise self.failureException(msg)
      AssertionError: [<CommandFailedEvent ('localhost', 27017) command: 'insert', operation_id: 143542612, duration_micros: 665, failure: {'errmsg': 'connection closed', 'errtype': 'AutoReconnect'}>, <CommandFailedEvent ('localhost', 27017) command: 'insert', operation_id: -501772513, duration_micros: 512, failure: {'errmsg': 'connection closed', 'errtype': 'AutoReconnect'}>] is not false
      

      I can reproduce this as far back as pymongo 3.6 with every major mongodb version which supports retryable writes 4.4.2, 4.2.9 and 3.6.20.

      Update: The following test which runs a retryable insert manually via Database.command also fails which indicates that this could be a server issue:

          def test_manual_retryable_write_insert(self):
              client = rs_or_single_client(retryWrites=True)
              client.test.command('insert', 'testcoll', documents=[{'a': 1}])
              from bson.int64 import Int64
              with client.start_session() as s:
                  client.test.command('insert', 'testcoll', documents=[{'a': 1}], txnNumber=Int64(1), session=s)
      

      Fails with:

      ERROR: test_manual_retryable_write_insert (test.test_retryable_writes.TestRetryableWrites)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "/Users/shane/git/mongo-python-driver/test/test_retryable_writes.py", line 467, in test_manual_retryable_write_insert
          client.test.command('insert', 'testcoll', documents=[{'a': 1}], txnNumber=Int64(2), session=s)
        File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 532, in command
          codec_options, session=session, **kwargs)
        File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 439, in _command
          client=self.__client)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", line 522, in command
          self._raise_connection_failure(error)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", line 677, in _raise_connection_failure
          raise error
      AutoReconnect: connection closed
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: