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

Avoid tight poll() loop on pyopenssl connections

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.2
    • Affects Version/s: None
    • Component/s: None
    • None

      When using pyopenssl, pymongo deals with WantReadError and WantWriteError by polling on the socket like this:

          def _call(self, call, *args, **kwargs):
              timeout = self.gettimeout()
              if timeout:
                  start = _time.monotonic()
              while True:
                  try:
                      return call(*args, **kwargs)
                  except _RETRY_ERRORS:  # Includes WantReadError and WantWriteError
                      self.socket_checker.select(self, True, True, timeout)
                      if timeout and _time.monotonic() - start > timeout:
                          raise _socket.timeout("timed out")
                      continue
      

      Notice that the socket_checker.select includes both read=True and write=True so it will return immediately if the socket is readable or writable. Instead a WantReadError should set read=True and write=False and a WantWriteError should set read=False and write=True. This will avoid a tight loop of calling poll/select when a read or write is required.

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

              Created:
              Updated:
              Resolved: