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

SSL timeouts should raise NetworkTimeout, not AutoReconnect

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • 3.4
    • None
    • None
    • Minor Change

    Description

      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.

      Attachments

        Issue Links

          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: