Gevent: SSLContext infinite recursion in Python 3.6 gevent-1.2.1

Created on 21 Feb 2017  路  7Comments  路  Source: gevent/gevent

  • gevent version: 1.2.1
  • Python version: 3.6
  • Operating System: Windows 7

Description:

I'm encountering the same problem as in https://github.com/gevent/gevent/issues/903
I couldn't reproduce the bug on Ubuntu-16.04 so it's probably a Windows issue?

What I've run:

I encountered the bug while running the example on signalR-client: https://github.com/TargetProcess/signalr-client-py

python3

Most helpful comment

@jamadden indeed, in the example "https://github.com/TargetProcess/signalr-client-py" adding

import gevent.monkey
gevent.monkey.patch_all()

before

from requests import Session
from signalr import Connection

makes the error go away.
Awesome, thanks!

All 7 comments

Can you post a minimal example and traceback? It's not clear to me why Windows would make a difference. We test under 3.6 on AppVeyor (Windows) and the SSL tests don't show that issue.

@jamadden yes, I got really confused as well and that's why I did a quick test on Ubuntu just to try isolate the problem. Here is the error I got, virtually the same as before:

Traceback (most recent call last):
  File "signalr_test.py", line 87, in <module>
    asyncio.gather(run())
  File "c:\program files (x86)\python36-32\Lib\asyncio\base_events.py", line 466, in run_until_complete
    return future.result()
  File "signalr_test.py", line 83, in run
    await signalRCore()
  File "signalr_test.py", line 38, in signalRCore
    connection.start()
  File "c:\program\path\venv\lib\site-packages\signalr\_connection.py", line 47, in start
    negotiate_data = self.__transport.negotiate()
  File "c:\program\path\venv\lib\site-packages\signalr\transports\_auto_transport.py", line 16, in negotiate
    negotiate_data = Transport.negotiate(self)
  File "c:\program\path\venv\lib\site-packages\signalr\transports\_transport.py", line 26, in negotiate
    negotiate = self._session.get(url)
  File "c:\program\path\venv\lib\site-packages\requests\sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "c:\program\path\venv\lib\site-packages\requests\sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "c:\program\path\venv\lib\site-packages\requests\sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "c:\program\path\venv\lib\site-packages\requests\adapters.py", line 423, in send
    timeout=timeout
  File "c:\program\path\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "c:\program\path\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 345, in _make_request
    self._validate_conn(conn)
  File "c:\program\path\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 844, in _validate_conn
    conn.connect()
  File "c:\program\path\venv\lib\site-packages\requests\packages\urllib3\connection.py", line 314, in connect
    cert_reqs=resolve_cert_reqs(self.cert_reqs),
  File "c:\program\path\venv\lib\site-packages\requests\packages\urllib3\util\ssl_.py", line 264, in create_urllib3_context
    context.options |= options
  File "c:\program files (x86)\python36-32\Lib\ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  File "c:\program files (x86)\python36-32\Lib\ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  File "c:\program files (x86)\python36-32\Lib\ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  [Previous line repeated 321 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

Can you post the output of the simple example provided in #903 (i.e., run exactly that in the console and paste the full console text)? That way we eliminate all the surrounding complexity of this app, asyncio, import order, etc.

And also the value of import gevent; print(gevent.__version__).

@jamadden that doesn't give any error. So maybe something to do with signalr-client?

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gevent.monkey
>>> gevent.monkey.patch_all()
>>> from requests.packages.urllib3.util.ssl_ import create_urllib3_context
>>> create_urllib3_context()
<gevent._ssl3.SSLContext object at 0x040E8430>
>>> print(gevent.__version__)
1.2.1

So maybe something to do with signalr-client?

That seems likely, or in the way it's being called anyway.

Note that if imports and monkey-patching are in the wrong order, its still possible to get this error on 3.6 with 1.2.1:

>>> from requests.packages.urllib3.util.ssl_ import create_urllib3_context
>>> import gevent
>>> print(gevent.__version__)
1.2.1
None
>>> import gevent.monkey
>>> gevent.monkey.patch_all()
None
>>> create_urllib3_context()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "//lib/python3.6/site-packages/requests/packages/urllib3/util/ssl_.py", line 264, in create_urllib3_context
    context.options |= options
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 459, in options
    super(SSLContext, SSLContext).options.__set__(self, value)
  [Previous line repeated 329 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

So it's probably something along those lines.

@jamadden indeed, in the example "https://github.com/TargetProcess/signalr-client-py" adding

import gevent.monkey
gevent.monkey.patch_all()

before

from requests import Session
from signalr import Connection

makes the error go away.
Awesome, thanks!

We're working on MacOS and getting a near identical stack trace.

Operating System: macOS 10.14.3
Python version: 3.6
gevent version: 1.2.2

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SiegelDaniel picture SiegelDaniel  路  7Comments

TylerMills picture TylerMills  路  10Comments

aelse picture aelse  路  8Comments

MuslimBeibytuly picture MuslimBeibytuly  路  3Comments

jamadden picture jamadden  路  9Comments