Re-raise socket.timeout errors if the deadline has already been execeeded

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      The handling of socket.timeout errors in receive_message currently looks like this:

          if deadline is not None:
              short_timeout = min(max(deadline - time.monotonic(), 0), _POLL_TIMEOUT)
          else:
              short_timeout = _POLL_TIMEOUT
          conn.set_conn_timeout(short_timeout)
      chunk_length = conn.conn.recv_into(mv[bytes_read:])
      ...
      except socket.timeout:
          if conn.cancel_context.cancelled:
              raise _OperationCancelled("operation cancelled") from None
          if _PYPY:
              # We reached the true deadline.
              raise
          continue
      ...
      

      This results in the driver attempting to read the socket an additional time once deadline - time.monotonic() is less than zero, meaning the deadline has already been reached. This can result in test failures such as PYTHON-4987, where the additional read is performed after an expected timeout instead of the timeout being raised as expected.

      Definition of done

      The driver should re-raise socket.timeout errors if the deadline has already been exceeded.

      Pitfalls

      N/A,

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

              Created:
              Updated:
              Resolved: