Skip to content

[3.11] gh-88177: Revert the new asyncio.sslproto implementation #95663

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

Closed
wants to merge 2 commits into from
Closed
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
60 changes: 5 additions & 55 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ Opening network connections
family=0, proto=0, flags=0, sock=None, \
local_addr=None, server_hostname=None, \
ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None, \
happy_eyeballs_delay=None, interleave=None)

Open a streaming transport connection to a given
Expand Down Expand Up @@ -464,10 +463,6 @@ Opening network connections
to wait for the TLS handshake to complete before aborting the connection.
``60.0`` seconds if ``None`` (default).

* *ssl_shutdown_timeout* is the time in seconds to wait for the SSL shutdown
to complete before aborting the connection. ``30.0`` seconds if ``None``
(default).

.. versionchanged:: 3.5

Added support for SSL/TLS in :class:`ProactorEventLoop`.
Expand Down Expand Up @@ -496,10 +491,6 @@ Opening network connections

For more information: https://tools.ietf.org/html/rfc6555

.. versionchanged:: 3.11

Added the *ssl_shutdown_timeout* parameter.

.. seealso::

The :func:`open_connection` function is a high-level alternative
Expand Down Expand Up @@ -585,8 +576,7 @@ Opening network connections

.. coroutinemethod:: loop.create_unix_connection(protocol_factory, \
path=None, *, ssl=None, sock=None, \
server_hostname=None, ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None)
server_hostname=None, ssl_handshake_timeout=None)

Create a Unix connection.

Expand All @@ -609,10 +599,6 @@ Opening network connections
Added the *ssl_handshake_timeout* parameter.
The *path* parameter can now be a :term:`path-like object`.

.. versionchanged:: 3.11

Added the *ssl_shutdown_timeout* parameter.


Creating network servers
^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -623,9 +609,7 @@ Creating network servers
flags=socket.AI_PASSIVE, \
sock=None, backlog=100, ssl=None, \
reuse_address=None, reuse_port=None, \
ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None, \
start_serving=True)
ssl_handshake_timeout=None, start_serving=True)

Create a TCP server (socket type :data:`~socket.SOCK_STREAM`) listening
on *port* of the *host* address.
Expand Down Expand Up @@ -685,10 +669,6 @@ Creating network servers
for the TLS handshake to complete before aborting the connection.
``60.0`` seconds if ``None`` (default).

* *ssl_shutdown_timeout* is the time in seconds to wait for the SSL shutdown
to complete before aborting the connection. ``30.0`` seconds if ``None``
(default).

* *start_serving* set to ``True`` (the default) causes the created server
to start accepting connections immediately. When set to ``False``,
the user should await on :meth:`Server.start_serving` or
Expand All @@ -709,10 +689,6 @@ Creating network servers
The socket option :py:data:`~socket.TCP_NODELAY` is set by default
for all TCP connections.

.. versionchanged:: 3.11

Added the *ssl_shutdown_timeout* parameter.

.. seealso::

The :func:`start_server` function is a higher-level alternative API
Expand All @@ -722,9 +698,7 @@ Creating network servers

.. coroutinemethod:: loop.create_unix_server(protocol_factory, path=None, \
*, sock=None, backlog=100, ssl=None, \
ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None, \
start_serving=True)
ssl_handshake_timeout=None, start_serving=True)

Similar to :meth:`loop.create_server` but works with the
:py:data:`~socket.AF_UNIX` socket family.
Expand All @@ -744,14 +718,8 @@ Creating network servers
Added the *ssl_handshake_timeout* and *start_serving* parameters.
The *path* parameter can now be a :class:`~pathlib.Path` object.

.. versionchanged:: 3.11

Added the *ssl_shutdown_timeout* parameter.


.. coroutinemethod:: loop.connect_accepted_socket(protocol_factory, \
sock, *, ssl=None, ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None)
sock, *, ssl=None, ssl_handshake_timeout=None)

Wrap an already accepted connection into a transport/protocol pair.

Expand All @@ -773,10 +741,6 @@ Creating network servers
wait for the SSL handshake to complete before aborting the connection.
``60.0`` seconds if ``None`` (default).

* *ssl_shutdown_timeout* is the time in seconds to wait for the SSL shutdown
to complete before aborting the connection. ``30.0`` seconds if ``None``
(default).

Returns a ``(transport, protocol)`` pair.

.. versionadded:: 3.5.3
Expand All @@ -785,10 +749,6 @@ Creating network servers

Added the *ssl_handshake_timeout* parameter.

.. versionchanged:: 3.11

Added the *ssl_shutdown_timeout* parameter.


Transferring files
^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -825,8 +785,7 @@ TLS Upgrade

.. coroutinemethod:: loop.start_tls(transport, protocol, \
sslcontext, *, server_side=False, \
server_hostname=None, ssl_handshake_timeout=None, \
ssl_shutdown_timeout=None)
server_hostname=None, ssl_handshake_timeout=None)

Upgrade an existing transport-based connection to TLS.

Expand All @@ -852,17 +811,8 @@ TLS Upgrade
wait for the TLS handshake to complete before aborting the connection.
``60.0`` seconds if ``None`` (default).

* *ssl_shutdown_timeout* is the time in seconds to wait for the SSL shutdown
to complete before aborting the connection. ``30.0`` seconds if ``None``
(default).

.. versionadded:: 3.7

.. versionchanged:: 3.11

Added the *ssl_shutdown_timeout* parameter.



Watching file descriptors
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
43 changes: 9 additions & 34 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ async def restore(self):
class Server(events.AbstractServer):

def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
ssl_handshake_timeout, ssl_shutdown_timeout=None):
ssl_handshake_timeout):
self._loop = loop
self._sockets = sockets
self._active_count = 0
Expand All @@ -283,7 +283,6 @@ def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
self._backlog = backlog
self._ssl_context = ssl_context
self._ssl_handshake_timeout = ssl_handshake_timeout
self._ssl_shutdown_timeout = ssl_shutdown_timeout
self._serving = False
self._serving_forever_fut = None

Expand Down Expand Up @@ -315,8 +314,7 @@ def _start_serving(self):
sock.listen(self._backlog)
self._loop._start_serving(
self._protocol_factory, sock, self._ssl_context,
self, self._backlog, self._ssl_handshake_timeout,
self._ssl_shutdown_timeout)
self, self._backlog, self._ssl_handshake_timeout)

def get_loop(self):
return self._loop
Expand Down Expand Up @@ -475,7 +473,6 @@ def _make_ssl_transport(
*, server_side=False, server_hostname=None,
extra=None, server=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None,
call_connection_made=True):
"""Create SSL transport."""
raise NotImplementedError
Expand Down Expand Up @@ -979,7 +976,6 @@ async def create_connection(
proto=0, flags=0, sock=None,
local_addr=None, server_hostname=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None,
happy_eyeballs_delay=None, interleave=None):
"""Connect to a TCP server.

Expand Down Expand Up @@ -1015,10 +1011,6 @@ async def create_connection(
raise ValueError(
'ssl_handshake_timeout is only meaningful with ssl')

if ssl_shutdown_timeout is not None and not ssl:
raise ValueError(
'ssl_shutdown_timeout is only meaningful with ssl')

if sock is not None:
_check_ssl_socket(sock)

Expand Down Expand Up @@ -1097,8 +1089,7 @@ async def create_connection(

transport, protocol = await self._create_connection_transport(
sock, protocol_factory, ssl, server_hostname,
ssl_handshake_timeout=ssl_handshake_timeout,
ssl_shutdown_timeout=ssl_shutdown_timeout)
ssl_handshake_timeout=ssl_handshake_timeout)
if self._debug:
# Get the socket from the transport because SSL transport closes
# the old socket and creates a new SSL socket
Expand All @@ -1110,8 +1101,7 @@ async def create_connection(
async def _create_connection_transport(
self, sock, protocol_factory, ssl,
server_hostname, server_side=False,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None):
ssl_handshake_timeout=None):

sock.setblocking(False)

Expand All @@ -1122,8 +1112,7 @@ async def _create_connection_transport(
transport = self._make_ssl_transport(
sock, protocol, sslcontext, waiter,
server_side=server_side, server_hostname=server_hostname,
ssl_handshake_timeout=ssl_handshake_timeout,
ssl_shutdown_timeout=ssl_shutdown_timeout)
ssl_handshake_timeout=ssl_handshake_timeout)
else:
transport = self._make_socket_transport(sock, protocol, waiter)

Expand Down Expand Up @@ -1214,8 +1203,7 @@ async def _sendfile_fallback(self, transp, file, offset, count):
async def start_tls(self, transport, protocol, sslcontext, *,
server_side=False,
server_hostname=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None):
ssl_handshake_timeout=None):
"""Upgrade transport to TLS.

Return a new transport that *protocol* should start using
Expand All @@ -1238,7 +1226,6 @@ async def start_tls(self, transport, protocol, sslcontext, *,
self, protocol, sslcontext, waiter,
server_side, server_hostname,
ssl_handshake_timeout=ssl_handshake_timeout,
ssl_shutdown_timeout=ssl_shutdown_timeout,
call_connection_made=False)

# Pause early so that "ssl_protocol.data_received()" doesn't
Expand Down Expand Up @@ -1424,7 +1411,6 @@ async def create_server(
reuse_address=None,
reuse_port=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None,
start_serving=True):
"""Create a TCP server.

Expand All @@ -1448,10 +1434,6 @@ async def create_server(
raise ValueError(
'ssl_handshake_timeout is only meaningful with ssl')

if ssl_shutdown_timeout is not None and ssl is None:
raise ValueError(
'ssl_shutdown_timeout is only meaningful with ssl')

if sock is not None:
_check_ssl_socket(sock)

Expand Down Expand Up @@ -1527,8 +1509,7 @@ async def create_server(
sock.setblocking(False)

server = Server(self, sockets, protocol_factory,
ssl, backlog, ssl_handshake_timeout,
ssl_shutdown_timeout)
ssl, backlog, ssl_handshake_timeout)
if start_serving:
server._start_serving()
# Skip one loop iteration so that all 'loop.add_reader'
Expand All @@ -1542,26 +1523,20 @@ async def create_server(
async def connect_accepted_socket(
self, protocol_factory, sock,
*, ssl=None,
ssl_handshake_timeout=None,
ssl_shutdown_timeout=None):
ssl_handshake_timeout=None):
if sock.type != socket.SOCK_STREAM:
raise ValueError(f'A Stream Socket was expected, got {sock!r}')

if ssl_handshake_timeout is not None and not ssl:
raise ValueError(
'ssl_handshake_timeout is only meaningful with ssl')

if ssl_shutdown_timeout is not None and not ssl:
raise ValueError(
'ssl_shutdown_timeout is only meaningful with ssl')

if sock is not None:
_check_ssl_socket(sock)

transport, protocol = await self._create_connection_transport(
sock, protocol_factory, ssl, '', server_side=True,
ssl_handshake_timeout=ssl_handshake_timeout,
ssl_shutdown_timeout=ssl_shutdown_timeout)
ssl_handshake_timeout=ssl_handshake_timeout)
if self._debug:
# Get the socket from the transport because SSL transport closes
# the old socket and creates a new SSL socket
Expand Down
7 changes: 0 additions & 7 deletions Lib/asyncio/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@
# The default timeout matches that of Nginx.
SSL_HANDSHAKE_TIMEOUT = 60.0

# Number of seconds to wait for SSL shutdown to complete
# The default timeout mimics lingering_time
SSL_SHUTDOWN_TIMEOUT = 30.0

# Used in sendfile fallback code. We use fallback for platforms
# that don't support sendfile, or for TLS connections.
SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 256

FLOW_CONTROL_HIGH_WATER_SSL_READ = 256 # KiB
FLOW_CONTROL_HIGH_WATER_SSL_WRITE = 512 # KiB

# The enum should be here to break circular dependencies between
# base_events and sslproto
class _SendfileMode(enum.Enum):
Expand Down
Loading