-
Notifications
You must be signed in to change notification settings - Fork 333
Closed
Description
With standard Python 3.2+ (not monkey patched) timeouts on ssl connections raise socket.timeout: The read operation timed out. socket.timeout is a standard class that applications can use to identify network timeouts vs other network errors. For example:
# import eventlet
# eventlet.monkey_patch()
import socket
import ssl
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
sock.settimeout(2) # Set timeout to 2 seconds.
sock.connect(("www.python.org", 443))
print('client socket connected')
client_context = ssl.create_default_context()
client_conn = client_context.wrap_socket(sock, server_hostname="www.python.org")
print('client TLS connected')
client_conn.read() # This line will timeout.The above example produces to following output:
$ python3 eventlet_ssl_timeout_bug.py
client socket connected
client TLS connected
Traceback (most recent call last):
File "eventlet_ssl_timeout_bug.py", line 14, in <module>
client_conn.read() # This line will timeout.
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1103, in read
return self._sslobj.read(len)
socket.timeout: The read operation timed out
However when we uncomment the monkey patching, eventlet raises the more general ssl.SSLError exception:
$ python eventlet_ssl_timeout_bug.py
client socket connected
client TLS connected
Traceback (most recent call last):
File "eventlet_ssl_timeout_bug.py", line 14, in <module>
client_conn.read() # This line will timeout.
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/eventlet/green/ssl.py", line 186, in read
return self._call_trampolining(
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/eventlet/green/ssl.py", line 164, in _call_trampolining
trampoline(self,
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/eventlet/hubs/__init__.py", line 159, in trampoline
return hub.switch()
File "/Users/shane/pymongo-pycharm-3.8/lib/python3.8/site-packages/eventlet/hubs/hub.py", line 313, in switch
return self.greenlet.switch()
ssl.SSLError: ('timed out',)
I would consider this a bug because the behavior differs from standard python and code that catches socket.timeout errors will no longer work as expected.
For related issues see:
- https://bugs.python.org/issue10272 where Python 3.2 changed ssl to raise socket.timeout on socket timeouts.
- https://jira.mongodb.org/browse/PYTHON-1157
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels