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

SSL timeouts should raise NetworkTimeout, not AutoReconnect

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Minor Change

      Before Python 3.2, the ssl module did not distinguish between timeouts and other ssl exceptions. See https://bugs.python.org/issue10272.

      In CPython 2.6 and 2.7 the ssl module raises a generic ssl.SSLError on socket timeouts. The error has a single attribute, message, set to 'The read operation timed out'.

      One improvement would be:

      def _raise_connection_failure(address, error):
          """Convert a socket.error to ConnectionFailure and raise it."""
          host, port = address
          # If connecting to a Unix socket, port will be None.
          if port is not None:
              msg = '%s:%d: %s' % (host, port, error)
          else:
              msg = '%s: %s' % (host, error)
          if isinstance(error, socket.timeout):
              raise NetworkTimeout(msg)
          elif isinstance(error, SSLError) and 'timed out' in error.message:
              raise NetworkTimeout(msg)
          else:
              raise AutoReconnect(msg)
      

      Research needs to be done to make sure this is portable on supported versions of CPython, PyPy, and PyPy3.

            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: