Skip to content

PYTHON-2163 Suppress ragged EOFs when using PyOpenSSL to match the stdlib #453

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 2 commits into from
Jul 2, 2020

Conversation

ShaneHarvey
Copy link
Member

Jira: https://jira.mongodb.org/browse/PYTHON-2163

This change does two things. First it fixes a bug where we were incorrectly not wrapping pyOpenSSL connection errors from wrap_socket. For example, before this change:

>>> client = MongoClient(ssl=True, serverSelectionTimeoutMS=1000).admin.command('ping')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 737, in command
    read_preference, session) as (sock_info, slave_ok):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1322, in _socket_for_reads
    server = self._select_server(read_preference, session)
  File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1275, in _select_server
    server = topology.select_server(server_selector)
  File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 243, in select_server
    address))
  File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 200, in select_servers
    selector, server_timeout, address)
  File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 217, in _select_servers_loop
    (self._error_message(selector), timeout, self.description))
pymongo.errors.ServerSelectionTimeoutError: (-1, 'Unexpected EOF'), Timeout: 1.0s, Topology Description: <TopologyDescription id: 5efe463ec658be84f88c0e33, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=SysCallError(-1, 'Unexpected EOF')>]>

After this change we correctly wrap the SysCallError in AutoReconnect("SSL handshake failed: ..."):

>>> client = MongoClient(ssl=True, serverSelectionTimeoutMS=1000).admin.command('ping')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shane/git/mongo-python-driver/pymongo/database.py", line 737, in command
    read_preference, session) as (sock_info, slave_ok):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1322, in _socket_for_reads
    server = self._select_server(read_preference, session)
  File "/Users/shane/git/mongo-python-driver/pymongo/mongo_client.py", line 1275, in _select_server
    server = topology.select_server(server_selector)
  File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 243, in select_server
    address))
  File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 200, in select_servers
    selector, server_timeout, address)
  File "/Users/shane/git/mongo-python-driver/pymongo/topology.py", line 217, in _select_servers_loop
    (self._error_message(selector), timeout, self.description))
pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: localhost:27017: (-1, 'Unexpected EOF'), Timeout: 1.0s, Topology Description: <TopologyDescription id: 5efe4624a92bae23d4ec5e73, topology_type: Single, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect("SSL handshake failed: localhost:27017: (-1, 'Unexpected EOF')")>]>

Second, this change adds support for suppress_ragged_eofs=True in pyOpenSSL reads/writes.

@ShaneHarvey ShaneHarvey requested a review from behackett July 2, 2020 20:44
@ShaneHarvey ShaneHarvey merged commit c2d6343 into mongodb:master Jul 2, 2020
@ShaneHarvey ShaneHarvey deleted the PYTHON-2163 branch July 2, 2020 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants