asyncio: fix SSL connections by using native TLS transport#884
Open
roydahan wants to merge 2 commits into
Open
asyncio: fix SSL connections by using native TLS transport#884roydahan wants to merge 2 commits into
roydahan wants to merge 2 commits into
Conversation
ScyllaDB has dropped support for SimpleStrategy. Update all CQL statements, test fixtures, examples, benchmarks, and management utilities to use NetworkTopologyStrategy instead. The SimpleStrategy class definition in cassandra/metadata.py is preserved for backward compatibility with Cassandra clusters.
Python 3.8+ rejects ssl.SSLSocket in asyncio's sock_sendall/sock_recv with TypeError. This caused the driver to fail connecting to ScyllaDB clusters requiring TLS, manifesting as 'protocol version 21 not supported' errors (0x15 = TLS Alert byte misread as protocol version). Fix by using asyncio's native TLS transport (loop.create_connection with ssl= parameter) instead of wrapping sockets with ssl.SSLContext.wrap_socket(). This preserves shard-aware port binding done during _initiate_connection(). Add _AsyncioProtocol to bridge asyncio's transport/protocol API back to Connection.process_io_buffer() for SSL data reads. Non-SSL connections continue using the existing sock_recv path. Fixes scylladb#330
Collaborator
|
@roydahan , please rebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SimpleStrategywithNetworkTopologyStrategyacross the codebase (ScyllaDB dropped SimpleStrategy support)loop.create_connection(ssl=)) instead ofssl.SSLContext.wrap_socket(), which Python 3.8+ rejects in asyncio'ssock_sendall/sock_recv0x15was misread as protocol version 21)Details
SimpleStrategy → NetworkTopologyStrategy
All CQL
CREATE KEYSPACEstatements, Python strategy objects, and test assertions updated. TheSimpleStrategyclass definition incassandra/metadata.pyis preserved for backward compatibility.AsyncioConnection SSL Fix
Problem: Python 3.8+ explicitly rejects
ssl.SSLSocketinasyncio.loop.sock_sendall()andsock_recv()withTypeError("ssl.SSLSocket is not supported"). The baseConnection._connect_socket()wraps the socket withssl.SSLContext.wrap_socket(), producing anSSLSocketthat asyncio refuses.Solution: Override
_connect_socket()inAsyncioConnectionto skip SSL wrapping, keeping a plain TCP socket. After the socket connects (preserving shard-aware port binding), upgrade to TLS asynchronously vialoop.create_connection(sock=, ssl=). A new_AsyncioProtocolclass bridges asyncio's transport/protocol API back toConnection.process_io_buffer()for reading. Writes usetransport.write()for SSL connections. Non-SSL connections are unchanged.Edge cases handled: SSL handshake failure properly unblocks the write coroutine and defuncts the connection.
Fixes #330