From ce115694a1ccede4025ffa67095966bb45acfd24 Mon Sep 17 00:00:00 2001 From: Shane Harvey Date: Fri, 19 Mar 2021 15:59:40 -0700 Subject: [PATCH] PYTHON-2615 Reinstate TLS network timeout workaround due to eventlet PYTHON-2616 Fix test_network_error_message when TLS is enabled. --- pymongo/pool.py | 6 ++++++ test/test_client.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pymongo/pool.py b/pymongo/pool.py index cc4c4ffce3..6dd3f2be48 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -237,6 +237,12 @@ def _raise_connection_failure(address, error, msg_prefix=None): msg = msg_prefix + msg if isinstance(error, socket.timeout): raise NetworkTimeout(msg) from error + elif isinstance(error, _SSLError) and 'timed out' in str(error): + # Eventlet does not distinguish TLS network timeouts from other + # SSLErrors (https://github.com/eventlet/eventlet/issues/692). + # Luckily, we can work around this limitation because the phrase + # 'timed out' appears in all the timeout related SSLErrors raised. + raise NetworkTimeout(msg) from error else: raise AutoReconnect(msg) from error diff --git a/test/test_client.py b/test/test_client.py index 3e656ab46e..31850f701e 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -1576,7 +1576,7 @@ def test_network_error_message(self): with self.fail_point({'mode': {'times': 1}, 'data': {'closeConnection': True, 'failCommands': ['find']}}): - expected = '%s:%s: connection closed' % client.address + expected = '%s:%s: ' % client.address with self.assertRaisesRegex(AutoReconnect, expected): client.pymongo_test.test.find_one({})