Skip to content

Commit 80adc13

Browse files
authored
PYTHON-2615 Reinstate TLS network timeout workaround due to eventlet (#581)
PYTHON-2616 Fix test_network_error_message when TLS is enabled.
1 parent 8ef4524 commit 80adc13

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pymongo/pool.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ def _raise_connection_failure(address, error, msg_prefix=None):
237237
msg = msg_prefix + msg
238238
if isinstance(error, socket.timeout):
239239
raise NetworkTimeout(msg) from error
240+
elif isinstance(error, _SSLError) and 'timed out' in str(error):
241+
# Eventlet does not distinguish TLS network timeouts from other
242+
# SSLErrors (https://github.com/eventlet/eventlet/issues/692).
243+
# Luckily, we can work around this limitation because the phrase
244+
# 'timed out' appears in all the timeout related SSLErrors raised.
245+
raise NetworkTimeout(msg) from error
240246
else:
241247
raise AutoReconnect(msg) from error
242248

test/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ def test_network_error_message(self):
15761576
with self.fail_point({'mode': {'times': 1},
15771577
'data': {'closeConnection': True,
15781578
'failCommands': ['find']}}):
1579-
expected = '%s:%s: connection closed' % client.address
1579+
expected = '%s:%s: ' % client.address
15801580
with self.assertRaisesRegex(AutoReconnect, expected):
15811581
client.pymongo_test.test.find_one({})
15821582

0 commit comments

Comments
 (0)