1

In a python 3.10.9 docker container, the app depends on a critical package what uses eventlet.monkey_patch(socket=True). Unfortunatelly this cause RecursionError: maximum recursion depth exceeded when requests.Session().get() called.

Here is the code snippet

import requests
from requests.adapters import HTTPAdapter

s = requests.Session()
s.mount('https://', HTTPAdapter(pool_connections=2))
s.get('https://stackoverflow.com/questions/34837026/whats-the-meaning-of-pool-connections-in-requests-adapters-httpadapter')
# <Response [200]>

import eventlet
eventlet.monkey_patch(socket=True)

s.get('https://stackoverflow.com/questions/34837026/whats-the-meaning-of-pool-connections-in-requests-adapters-httpadapter')
# <Response [200]>

s.get('https://www.google.com/')
# RecursionError: maximum recursion depth exceeded

s.get('https://stackoverflow.com/questions/34837026/whats-the-meaning-of-pool-connections-in-requests-adapters-httpadapter')
# <Response [200]>

Is there any possible way to make urllib3.HTTPSConnection.connect(self) be coperative with a patched socket.

So far the only trick I found is to warm up the connection pools before monkey_patch applied.

I must deal witheventlet.monkey_patch(socket=True). It is not an option to replace it with gevent or rewrite.

oliver nadj
  • 788
  • 7
  • 21

0 Answers0