[Build Failure] test/test_network_layer.py::TestReceiveMessage::test_unknown_opcode_raises

XMLWordPrintableJSON

    • Type: Build Failure
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Python Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Name of Failure:

      test/test_network_layer.py::TestReceiveMessage::test_unknown_opcode_raises

      Link to task:

      https://github.com/mongodb/mongo-python-driver/actions/runs/28890866458/job/85702937658?pr=2911

      Context of when and why the failure occurred:

      A race condition between the test suite's background client_context client's monitoring/heartbeat threads and the patched receive_message call in the test. If the client's call triggers after the patch is applied but before the test can call receive_message, the failure occurs.

      Stack trace:

      ________________ TestReceiveMessage.test_unknown_opcode_raises _________________
      
      self = <test.test_network_layer.TestReceiveMessage testMethod=test_unknown_opcode_raises>
      
          def test_unknown_opcode_raises(self):
              with patch.object(
                  network_layer,
                  "receive_data",
                  side_effect=[
                      pack_msg_header(length=20, request_id=0, response_to=0, op_code=9999),
                      b"data",
                  ],
              ):
                  with self.assertRaisesRegex(ProtocolError, "Got opcode"):
      >               network_layer.receive_message(_make_conn(), request_id=None)
                                    ^^^^^^^^^^^^^^^
      
      test/test_network_layer.py:86: 
      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
      
          def receive_message(
              conn: Connection, request_id: Optional[int], max_message_size: int = MAX_MESSAGE_SIZE
          ) -> _OpMsg:
              """Receive a raw BSON message or raise socket.error."""
              if _csot.get_timeout():
                  deadline = _csot.get_deadline()
              else:
                  timeout = conn.conn.gettimeout()
                  if timeout:
                      deadline = time.monotonic() + timeout
                  else:
                      deadline = None
              # Ignore the response's request id.
      >       length, _, response_to, op_code = _UNPACK_HEADER(receive_data(conn, 16, deadline))
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      E       struct.error: unpack str size too short for format
      
      pymongo/network_layer.py:762: error
      

            Assignee:
            Noah Stapp
            Reporter:
            Noah Stapp
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: