Skip to content

PYTHON-2615 Reinstate TLS network timeout workaround due to eventlet #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pymongo/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering since this is only occurring when eventlet is installed should we check whether eventlet is installed (I don't know if its possible - I feel like it should be) inside this elif?

Copy link
Member Author

@ShaneHarvey ShaneHarvey Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we can't check if eventlet is installed. Merely importing eventlet can have side effects like we saw in the dnspython 2.0 vs eventlet bug (see #484 (comment)).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.
Using __import__ will actually eliminate any side effects as it doesn't mess with the current global/local namespaces (unless instructed to do so) but I take your point that checking eventlet in any form would present a risk with minimal reward.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think __import__ can prevent the types of issues we saw in #484 (comment)

# 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

Expand Down
2 changes: 1 addition & 1 deletion test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({})

Expand Down