psf / psf/requests

requests treats urllib3's SSL handshake timeout as ReadTimeout

Open
#4,590 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
54.3k
Forks
10.4k
Avg merge
16h 43m
Merged PRs (30d)
3

Description

Expected Result

When connecting to a remote machine via SSL/TLS, and SSL handshake timeout happens, I expect to have SSLError or ConnectionError exception.

Actual Result

requests raises ReadTimeout

Reproduction Steps

I don't know how to reproduce this, but I have a real stacktrace (most recent call first):

timeout: _ssl.c:704: The handshake operation timed out
  File "urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "urllib3/connectionpool.py", line 850, in _validate_conn
    conn.connect()
  File "urllib3/connection.py", line 326, in connect
    ssl_context=context)
  File "urllib3/util/ssl_.py", line 329, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "python3.5/ssl.py", line 385, in wrap_socket
    _context=self)
  File "python3.5/ssl.py", line 760, in __init__
    self.do_handshake()
  File "python3.5/ssl.py", line 996, in do_handshake
    self._sslobj.do_handshake()
  File "python3.5/ssl.py", line 641, in do_handshake
    self._sslobj.do_handshake()
ReadTimeoutError: HTTPSConnectionPool(host='somehost.com', port=443): Read timed out. (read timeout=5)
  File "requests/adapters.py", line 440, in send
    timeout=timeout
  File "urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "urllib3/util/retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "urllib3/packages/six.py", line 686, in reraise
    raise value
  File "urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "urllib3/connectionpool.py", line 349, in _make_request
    self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
  File "urllib3/connectionpool.py", line 309, in _raise_timeout
    raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
ReadTimeout: HTTPSConnectionPool(host='somehost.com', port=443): Read timed out. (read timeout=5)
  File "wsa/external/soap.py", line 234, in call
    response = command(**params)
  File "zeep/client.py", line 45, in __call__
    self._op_name, args, kwargs)
  File "zeep/wsdl/bindings/soap.py", line 113, in send
    options['address'], envelope, http_headers)
  File "zeep/transports.py", line 95, in post_xml
    return self.post(address, message, headers)
  File "wsa/external/soap.py", line 75, in post
    return super(NonPersistentTransport, self).post(address, message, headers)
  File "zeep/transports.py", line 67, in post
    timeout=self.operation_timeout)
  File "requests/sessions.py", line 555, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "raven/breadcrumbs.py", line 297, in send
    resp = real_send(self, request, *args, **kwargs)
  File "requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "requests/adapters.py", line 521, in send
    raise ReadTimeout(e, request=request)

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.5.3"
  },
  "platform": {
    "release": "3.10.0-693.5.2.el7.x86_64",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "1000105f"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": false
}
$ openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
$ cat /etc/redhat-release
$ uname -spori
OS: CentOS Linux release 7.4.1708 (Core), Linux 3.10.0-693.5.2.el7.x86_64 x86_64 x86_64 GNU/Linux

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in requests/adapters.py at the exception handling and trace back through urllib3/connectionpool.py's _raise_timeout using the supplied stacktrace. Check how SSL handshake timeouts are classified, then add regression coverage for the reported exception type and verify the existing test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.