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

Avoid tight poll() loop on pyopenssl connections

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Unknown
    • Resolution: Fixed
    • None
    • 4.2
    • None
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: