Skip to content

Commit 7719953

Browse files
authored
bpo-44011: Revert "New asyncio ssl implementation (GH-17975)" (GH-25848)
This reverts commit 5fb06ed and all subsequent dependent commits.
1 parent 3949428 commit 7719953

12 files changed

+527
-2480
lines changed

Lib/asyncio/base_events.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ async def restore(self):
273273
class Server(events.AbstractServer):
274274

275275
def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
276-
ssl_handshake_timeout, ssl_shutdown_timeout=None):
276+
ssl_handshake_timeout):
277277
self._loop = loop
278278
self._sockets = sockets
279279
self._active_count = 0
@@ -282,7 +282,6 @@ def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
282282
self._backlog = backlog
283283
self._ssl_context = ssl_context
284284
self._ssl_handshake_timeout = ssl_handshake_timeout
285-
self._ssl_shutdown_timeout = ssl_shutdown_timeout
286285
self._serving = False
287286
self._serving_forever_fut = None
288287

@@ -314,8 +313,7 @@ def _start_serving(self):
314313
sock.listen(self._backlog)
315314
self._loop._start_serving(
316315
self._protocol_factory, sock, self._ssl_context,
317-
self, self._backlog, self._ssl_handshake_timeout,
318-
self._ssl_shutdown_timeout)
316+
self, self._backlog, self._ssl_handshake_timeout)
319317

320318
def get_loop(self):
321319
return self._loop
@@ -469,7 +467,6 @@ def _make_ssl_transport(
469467
*, server_side=False, server_hostname=None,
470468
extra=None, server=None,
471469
ssl_handshake_timeout=None,
472-
ssl_shutdown_timeout=None,
473470
call_connection_made=True):
474471
"""Create SSL transport."""
475472
raise NotImplementedError
@@ -972,7 +969,6 @@ async def create_connection(
972969
proto=0, flags=0, sock=None,
973970
local_addr=None, server_hostname=None,
974971
ssl_handshake_timeout=None,
975-
ssl_shutdown_timeout=None,
976972
happy_eyeballs_delay=None, interleave=None):
977973
"""Connect to a TCP server.
978974
@@ -1008,10 +1004,6 @@ async def create_connection(
10081004
raise ValueError(
10091005
'ssl_handshake_timeout is only meaningful with ssl')
10101006

1011-
if ssl_shutdown_timeout is not None and not ssl:
1012-
raise ValueError(
1013-
'ssl_shutdown_timeout is only meaningful with ssl')
1014-
10151007
if happy_eyeballs_delay is not None and interleave is None:
10161008
# If using happy eyeballs, default to interleave addresses by family
10171009
interleave = 1
@@ -1087,8 +1079,7 @@ async def create_connection(
10871079

10881080
transport, protocol = await self._create_connection_transport(
10891081
sock, protocol_factory, ssl, server_hostname,
1090-
ssl_handshake_timeout=ssl_handshake_timeout,
1091-
ssl_shutdown_timeout=ssl_shutdown_timeout)
1082+
ssl_handshake_timeout=ssl_handshake_timeout)
10921083
if self._debug:
10931084
# Get the socket from the transport because SSL transport closes
10941085
# the old socket and creates a new SSL socket
@@ -1100,8 +1091,7 @@ async def create_connection(
11001091
async def _create_connection_transport(
11011092
self, sock, protocol_factory, ssl,
11021093
server_hostname, server_side=False,
1103-
ssl_handshake_timeout=None,
1104-
ssl_shutdown_timeout=None):
1094+
ssl_handshake_timeout=None):
11051095

11061096
sock.setblocking(False)
11071097

@@ -1112,8 +1102,7 @@ async def _create_connection_transport(
11121102
transport = self._make_ssl_transport(
11131103
sock, protocol, sslcontext, waiter,
11141104
server_side=server_side, server_hostname=server_hostname,
1115-
ssl_handshake_timeout=ssl_handshake_timeout,
1116-
ssl_shutdown_timeout=ssl_shutdown_timeout)
1105+
ssl_handshake_timeout=ssl_handshake_timeout)
11171106
else:
11181107
transport = self._make_socket_transport(sock, protocol, waiter)
11191108

@@ -1204,8 +1193,7 @@ async def _sendfile_fallback(self, transp, file, offset, count):
12041193
async def start_tls(self, transport, protocol, sslcontext, *,
12051194
server_side=False,
12061195
server_hostname=None,
1207-
ssl_handshake_timeout=None,
1208-
ssl_shutdown_timeout=None):
1196+
ssl_handshake_timeout=None):
12091197
"""Upgrade transport to TLS.
12101198
12111199
Return a new transport that *protocol* should start using
@@ -1228,7 +1216,6 @@ async def start_tls(self, transport, protocol, sslcontext, *,
12281216
self, protocol, sslcontext, waiter,
12291217
server_side, server_hostname,
12301218
ssl_handshake_timeout=ssl_handshake_timeout,
1231-
ssl_shutdown_timeout=ssl_shutdown_timeout,
12321219
call_connection_made=False)
12331220

12341221
# Pause early so that "ssl_protocol.data_received()" doesn't
@@ -1427,7 +1414,6 @@ async def create_server(
14271414
reuse_address=None,
14281415
reuse_port=None,
14291416
ssl_handshake_timeout=None,
1430-
ssl_shutdown_timeout=None,
14311417
start_serving=True):
14321418
"""Create a TCP server.
14331419
@@ -1451,10 +1437,6 @@ async def create_server(
14511437
raise ValueError(
14521438
'ssl_handshake_timeout is only meaningful with ssl')
14531439

1454-
if ssl_shutdown_timeout is not None and ssl is None:
1455-
raise ValueError(
1456-
'ssl_shutdown_timeout is only meaningful with ssl')
1457-
14581440
if host is not None or port is not None:
14591441
if sock is not None:
14601442
raise ValueError(
@@ -1527,8 +1509,7 @@ async def create_server(
15271509
sock.setblocking(False)
15281510

15291511
server = Server(self, sockets, protocol_factory,
1530-
ssl, backlog, ssl_handshake_timeout,
1531-
ssl_shutdown_timeout)
1512+
ssl, backlog, ssl_handshake_timeout)
15321513
if start_serving:
15331514
server._start_serving()
15341515
# Skip one loop iteration so that all 'loop.add_reader'
@@ -1542,23 +1523,17 @@ async def create_server(
15421523
async def connect_accepted_socket(
15431524
self, protocol_factory, sock,
15441525
*, ssl=None,
1545-
ssl_handshake_timeout=None,
1546-
ssl_shutdown_timeout=None):
1526+
ssl_handshake_timeout=None):
15471527
if sock.type != socket.SOCK_STREAM:
15481528
raise ValueError(f'A Stream Socket was expected, got {sock!r}')
15491529

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

1554-
if ssl_shutdown_timeout is not None and not ssl:
1555-
raise ValueError(
1556-
'ssl_shutdown_timeout is only meaningful with ssl')
1557-
15581534
transport, protocol = await self._create_connection_transport(
15591535
sock, protocol_factory, ssl, '', server_side=True,
1560-
ssl_handshake_timeout=ssl_handshake_timeout,
1561-
ssl_shutdown_timeout=ssl_shutdown_timeout)
1536+
ssl_handshake_timeout=ssl_handshake_timeout)
15621537
if self._debug:
15631538
# Get the socket from the transport because SSL transport closes
15641539
# the old socket and creates a new SSL socket

Lib/asyncio/constants.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@
1515
# The default timeout matches that of Nginx.
1616
SSL_HANDSHAKE_TIMEOUT = 60.0
1717

18-
# Number of seconds to wait for SSL shutdown to complete
19-
# The default timeout mimics lingering_time
20-
SSL_SHUTDOWN_TIMEOUT = 30.0
21-
2218
# Used in sendfile fallback code. We use fallback for platforms
2319
# that don't support sendfile, or for TLS connections.
2420
SENDFILE_FALLBACK_READBUFFER_SIZE = 1024 * 256
2521

26-
FLOW_CONTROL_HIGH_WATER_SSL_READ = 256 # KiB
27-
FLOW_CONTROL_HIGH_WATER_SSL_WRITE = 512 # KiB
28-
2922
# The enum should be here to break circular dependencies between
3023
# base_events and sslproto
3124
class _SendfileMode(enum.Enum):

Lib/asyncio/events.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ async def create_connection(
304304
flags=0, sock=None, local_addr=None,
305305
server_hostname=None,
306306
ssl_handshake_timeout=None,
307-
ssl_shutdown_timeout=None,
308307
happy_eyeballs_delay=None, interleave=None):
309308
raise NotImplementedError
310309

@@ -314,7 +313,6 @@ async def create_server(
314313
flags=socket.AI_PASSIVE, sock=None, backlog=100,
315314
ssl=None, reuse_address=None, reuse_port=None,
316315
ssl_handshake_timeout=None,
317-
ssl_shutdown_timeout=None,
318316
start_serving=True):
319317
"""A coroutine which creates a TCP server bound to host and port.
320318
@@ -355,10 +353,6 @@ async def create_server(
355353
will wait for completion of the SSL handshake before aborting the
356354
connection. Default is 60s.
357355
358-
ssl_shutdown_timeout is the time in seconds that an SSL server
359-
will wait for completion of the SSL shutdown procedure
360-
before aborting the connection. Default is 30s.
361-
362356
start_serving set to True (default) causes the created server
363357
to start accepting connections immediately. When set to False,
364358
the user should await Server.start_serving() or Server.serve_forever()
@@ -377,8 +371,7 @@ async def sendfile(self, transport, file, offset=0, count=None,
377371
async def start_tls(self, transport, protocol, sslcontext, *,
378372
server_side=False,
379373
server_hostname=None,
380-
ssl_handshake_timeout=None,
381-
ssl_shutdown_timeout=None):
374+
ssl_handshake_timeout=None):
382375
"""Upgrade a transport to TLS.
383376
384377
Return a new transport that *protocol* should start using
@@ -390,15 +383,13 @@ async def create_unix_connection(
390383
self, protocol_factory, path=None, *,
391384
ssl=None, sock=None,
392385
server_hostname=None,
393-
ssl_handshake_timeout=None,
394-
ssl_shutdown_timeout=None):
386+
ssl_handshake_timeout=None):
395387
raise NotImplementedError
396388

397389
async def create_unix_server(
398390
self, protocol_factory, path=None, *,
399391
sock=None, backlog=100, ssl=None,
400392
ssl_handshake_timeout=None,
401-
ssl_shutdown_timeout=None,
402393
start_serving=True):
403394
"""A coroutine which creates a UNIX Domain Socket server.
404395
@@ -420,9 +411,6 @@ async def create_unix_server(
420411
ssl_handshake_timeout is the time in seconds that an SSL server
421412
will wait for the SSL handshake to complete (defaults to 60s).
422413
423-
ssl_shutdown_timeout is the time in seconds that an SSL server
424-
will wait for the SSL shutdown to finish (defaults to 30s).
425-
426414
start_serving set to True (default) causes the created server
427415
to start accepting connections immediately. When set to False,
428416
the user should await Server.start_serving() or Server.serve_forever()
@@ -433,8 +421,7 @@ async def create_unix_server(
433421
async def connect_accepted_socket(
434422
self, protocol_factory, sock,
435423
*, ssl=None,
436-
ssl_handshake_timeout=None,
437-
ssl_shutdown_timeout=None):
424+
ssl_handshake_timeout=None):
438425
"""Handle an accepted connection.
439426
440427
This is used by servers that accept connections outside of

Lib/asyncio/proactor_events.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,11 @@ def _make_ssl_transport(
642642
self, rawsock, protocol, sslcontext, waiter=None,
643643
*, server_side=False, server_hostname=None,
644644
extra=None, server=None,
645-
ssl_handshake_timeout=None,
646-
ssl_shutdown_timeout=None):
645+
ssl_handshake_timeout=None):
647646
ssl_protocol = sslproto.SSLProtocol(
648647
self, protocol, sslcontext, waiter,
649648
server_side, server_hostname,
650-
ssl_handshake_timeout=ssl_handshake_timeout,
651-
ssl_shutdown_timeout=ssl_shutdown_timeout)
649+
ssl_handshake_timeout=ssl_handshake_timeout)
652650
_ProactorSocketTransport(self, rawsock, ssl_protocol,
653651
extra=extra, server=server)
654652
return ssl_protocol._app_transport
@@ -814,8 +812,7 @@ def _write_to_self(self):
814812

815813
def _start_serving(self, protocol_factory, sock,
816814
sslcontext=None, server=None, backlog=100,
817-
ssl_handshake_timeout=None,
818-
ssl_shutdown_timeout=None):
815+
ssl_handshake_timeout=None):
819816

820817
def loop(f=None):
821818
try:
@@ -829,8 +826,7 @@ def loop(f=None):
829826
self._make_ssl_transport(
830827
conn, protocol, sslcontext, server_side=True,
831828
extra={'peername': addr}, server=server,
832-
ssl_handshake_timeout=ssl_handshake_timeout,
833-
ssl_shutdown_timeout=ssl_shutdown_timeout)
829+
ssl_handshake_timeout=ssl_handshake_timeout)
834830
else:
835831
self._make_socket_transport(
836832
conn, protocol,

Lib/asyncio/selector_events.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,11 @@ def _make_ssl_transport(
7070
self, rawsock, protocol, sslcontext, waiter=None,
7171
*, server_side=False, server_hostname=None,
7272
extra=None, server=None,
73-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
74-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT,
75-
):
73+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
7674
ssl_protocol = sslproto.SSLProtocol(
77-
self, protocol, sslcontext, waiter,
78-
server_side, server_hostname,
79-
ssl_handshake_timeout=ssl_handshake_timeout,
80-
ssl_shutdown_timeout=ssl_shutdown_timeout
81-
)
75+
self, protocol, sslcontext, waiter,
76+
server_side, server_hostname,
77+
ssl_handshake_timeout=ssl_handshake_timeout)
8278
_SelectorSocketTransport(self, rawsock, ssl_protocol,
8379
extra=extra, server=server)
8480
return ssl_protocol._app_transport
@@ -150,17 +146,15 @@ def _write_to_self(self):
150146

151147
def _start_serving(self, protocol_factory, sock,
152148
sslcontext=None, server=None, backlog=100,
153-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
154-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT):
149+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
155150
self._add_reader(sock.fileno(), self._accept_connection,
156151
protocol_factory, sock, sslcontext, server, backlog,
157-
ssl_handshake_timeout, ssl_shutdown_timeout)
152+
ssl_handshake_timeout)
158153

159154
def _accept_connection(
160155
self, protocol_factory, sock,
161156
sslcontext=None, server=None, backlog=100,
162-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
163-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT):
157+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
164158
# This method is only called once for each event loop tick where the
165159
# listening socket has triggered an EVENT_READ. There may be multiple
166160
# connections waiting for an .accept() so it is called in a loop.
@@ -191,22 +185,20 @@ def _accept_connection(
191185
self.call_later(constants.ACCEPT_RETRY_DELAY,
192186
self._start_serving,
193187
protocol_factory, sock, sslcontext, server,
194-
backlog, ssl_handshake_timeout,
195-
ssl_shutdown_timeout)
188+
backlog, ssl_handshake_timeout)
196189
else:
197190
raise # The event loop will catch, log and ignore it.
198191
else:
199192
extra = {'peername': addr}
200193
accept = self._accept_connection2(
201194
protocol_factory, conn, extra, sslcontext, server,
202-
ssl_handshake_timeout, ssl_shutdown_timeout)
195+
ssl_handshake_timeout)
203196
self.create_task(accept)
204197

205198
async def _accept_connection2(
206199
self, protocol_factory, conn, extra,
207200
sslcontext=None, server=None,
208-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
209-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT):
201+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
210202
protocol = None
211203
transport = None
212204
try:
@@ -216,8 +208,7 @@ async def _accept_connection2(
216208
transport = self._make_ssl_transport(
217209
conn, protocol, sslcontext, waiter=waiter,
218210
server_side=True, extra=extra, server=server,
219-
ssl_handshake_timeout=ssl_handshake_timeout,
220-
ssl_shutdown_timeout=ssl_shutdown_timeout)
211+
ssl_handshake_timeout=ssl_handshake_timeout)
221212
else:
222213
transport = self._make_socket_transport(
223214
conn, protocol, waiter=waiter, extra=extra,

0 commit comments

Comments
 (0)