Skip to content

Commit 07e6a8f

Browse files
committed
Revert "bpo-44011: New asyncio ssl implementation (python#31275)"
This reverts commit 13c10bf.
1 parent 5ac3d0f commit 07e6a8f

File tree

11 files changed

+527
-2479
lines changed

11 files changed

+527
-2479
lines changed

Lib/asyncio/base_events.py

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

276276
def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
277-
ssl_handshake_timeout, ssl_shutdown_timeout=None):
277+
ssl_handshake_timeout):
278278
self._loop = loop
279279
self._sockets = sockets
280280
self._active_count = 0
@@ -283,7 +283,6 @@ def __init__(self, loop, sockets, protocol_factory, ssl_context, backlog,
283283
self._backlog = backlog
284284
self._ssl_context = ssl_context
285285
self._ssl_handshake_timeout = ssl_handshake_timeout
286-
self._ssl_shutdown_timeout = ssl_shutdown_timeout
287286
self._serving = False
288287
self._serving_forever_fut = None
289288

@@ -315,8 +314,7 @@ def _start_serving(self):
315314
sock.listen(self._backlog)
316315
self._loop._start_serving(
317316
self._protocol_factory, sock, self._ssl_context,
318-
self, self._backlog, self._ssl_handshake_timeout,
319-
self._ssl_shutdown_timeout)
317+
self, self._backlog, self._ssl_handshake_timeout)
320318

321319
def get_loop(self):
322320
return self._loop
@@ -475,7 +473,6 @@ def _make_ssl_transport(
475473
*, server_side=False, server_hostname=None,
476474
extra=None, server=None,
477475
ssl_handshake_timeout=None,
478-
ssl_shutdown_timeout=None,
479476
call_connection_made=True):
480477
"""Create SSL transport."""
481478
raise NotImplementedError
@@ -979,7 +976,6 @@ async def create_connection(
979976
proto=0, flags=0, sock=None,
980977
local_addr=None, server_hostname=None,
981978
ssl_handshake_timeout=None,
982-
ssl_shutdown_timeout=None,
983979
happy_eyeballs_delay=None, interleave=None):
984980
"""Connect to a TCP server.
985981
@@ -1015,10 +1011,6 @@ async def create_connection(
10151011
raise ValueError(
10161012
'ssl_handshake_timeout is only meaningful with ssl')
10171013

1018-
if ssl_shutdown_timeout is not None and not ssl:
1019-
raise ValueError(
1020-
'ssl_shutdown_timeout is only meaningful with ssl')
1021-
10221014
if sock is not None:
10231015
_check_ssl_socket(sock)
10241016

@@ -1097,8 +1089,7 @@ async def create_connection(
10971089

10981090
transport, protocol = await self._create_connection_transport(
10991091
sock, protocol_factory, ssl, server_hostname,
1100-
ssl_handshake_timeout=ssl_handshake_timeout,
1101-
ssl_shutdown_timeout=ssl_shutdown_timeout)
1092+
ssl_handshake_timeout=ssl_handshake_timeout)
11021093
if self._debug:
11031094
# Get the socket from the transport because SSL transport closes
11041095
# the old socket and creates a new SSL socket
@@ -1110,8 +1101,7 @@ async def create_connection(
11101101
async def _create_connection_transport(
11111102
self, sock, protocol_factory, ssl,
11121103
server_hostname, server_side=False,
1113-
ssl_handshake_timeout=None,
1114-
ssl_shutdown_timeout=None):
1104+
ssl_handshake_timeout=None):
11151105

11161106
sock.setblocking(False)
11171107

@@ -1122,8 +1112,7 @@ async def _create_connection_transport(
11221112
transport = self._make_ssl_transport(
11231113
sock, protocol, sslcontext, waiter,
11241114
server_side=server_side, server_hostname=server_hostname,
1125-
ssl_handshake_timeout=ssl_handshake_timeout,
1126-
ssl_shutdown_timeout=ssl_shutdown_timeout)
1115+
ssl_handshake_timeout=ssl_handshake_timeout)
11271116
else:
11281117
transport = self._make_socket_transport(sock, protocol, waiter)
11291118

@@ -1214,8 +1203,7 @@ async def _sendfile_fallback(self, transp, file, offset, count):
12141203
async def start_tls(self, transport, protocol, sslcontext, *,
12151204
server_side=False,
12161205
server_hostname=None,
1217-
ssl_handshake_timeout=None,
1218-
ssl_shutdown_timeout=None):
1206+
ssl_handshake_timeout=None):
12191207
"""Upgrade transport to TLS.
12201208
12211209
Return a new transport that *protocol* should start using
@@ -1238,7 +1226,6 @@ async def start_tls(self, transport, protocol, sslcontext, *,
12381226
self, protocol, sslcontext, waiter,
12391227
server_side, server_hostname,
12401228
ssl_handshake_timeout=ssl_handshake_timeout,
1241-
ssl_shutdown_timeout=ssl_shutdown_timeout,
12421229
call_connection_made=False)
12431230

12441231
# Pause early so that "ssl_protocol.data_received()" doesn't
@@ -1424,7 +1411,6 @@ async def create_server(
14241411
reuse_address=None,
14251412
reuse_port=None,
14261413
ssl_handshake_timeout=None,
1427-
ssl_shutdown_timeout=None,
14281414
start_serving=True):
14291415
"""Create a TCP server.
14301416
@@ -1448,10 +1434,6 @@ async def create_server(
14481434
raise ValueError(
14491435
'ssl_handshake_timeout is only meaningful with ssl')
14501436

1451-
if ssl_shutdown_timeout is not None and ssl is None:
1452-
raise ValueError(
1453-
'ssl_shutdown_timeout is only meaningful with ssl')
1454-
14551437
if sock is not None:
14561438
_check_ssl_socket(sock)
14571439

@@ -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,26 +1523,20 @@ 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
if sock is not None:
15591535
_check_ssl_socket(sock)
15601536

15611537
transport, protocol = await self._create_connection_transport(
15621538
sock, protocol_factory, ssl, '', server_side=True,
1563-
ssl_handshake_timeout=ssl_handshake_timeout,
1564-
ssl_shutdown_timeout=ssl_shutdown_timeout)
1539+
ssl_handshake_timeout=ssl_handshake_timeout)
15651540
if self._debug:
15661541
# Get the socket from the transport because SSL transport closes
15671542
# 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
@@ -303,7 +303,6 @@ async def create_connection(
303303
flags=0, sock=None, local_addr=None,
304304
server_hostname=None,
305305
ssl_handshake_timeout=None,
306-
ssl_shutdown_timeout=None,
307306
happy_eyeballs_delay=None, interleave=None):
308307
raise NotImplementedError
309308

@@ -313,7 +312,6 @@ async def create_server(
313312
flags=socket.AI_PASSIVE, sock=None, backlog=100,
314313
ssl=None, reuse_address=None, reuse_port=None,
315314
ssl_handshake_timeout=None,
316-
ssl_shutdown_timeout=None,
317315
start_serving=True):
318316
"""A coroutine which creates a TCP server bound to host and port.
319317
@@ -354,10 +352,6 @@ async def create_server(
354352
will wait for completion of the SSL handshake before aborting the
355353
connection. Default is 60s.
356354
357-
ssl_shutdown_timeout is the time in seconds that an SSL server
358-
will wait for completion of the SSL shutdown procedure
359-
before aborting the connection. Default is 30s.
360-
361355
start_serving set to True (default) causes the created server
362356
to start accepting connections immediately. When set to False,
363357
the user should await Server.start_serving() or Server.serve_forever()
@@ -376,8 +370,7 @@ async def sendfile(self, transport, file, offset=0, count=None,
376370
async def start_tls(self, transport, protocol, sslcontext, *,
377371
server_side=False,
378372
server_hostname=None,
379-
ssl_handshake_timeout=None,
380-
ssl_shutdown_timeout=None):
373+
ssl_handshake_timeout=None):
381374
"""Upgrade a transport to TLS.
382375
383376
Return a new transport that *protocol* should start using
@@ -389,15 +382,13 @@ async def create_unix_connection(
389382
self, protocol_factory, path=None, *,
390383
ssl=None, sock=None,
391384
server_hostname=None,
392-
ssl_handshake_timeout=None,
393-
ssl_shutdown_timeout=None):
385+
ssl_handshake_timeout=None):
394386
raise NotImplementedError
395387

396388
async def create_unix_server(
397389
self, protocol_factory, path=None, *,
398390
sock=None, backlog=100, ssl=None,
399391
ssl_handshake_timeout=None,
400-
ssl_shutdown_timeout=None,
401392
start_serving=True):
402393
"""A coroutine which creates a UNIX Domain Socket server.
403394
@@ -419,9 +410,6 @@ async def create_unix_server(
419410
ssl_handshake_timeout is the time in seconds that an SSL server
420411
will wait for the SSL handshake to complete (defaults to 60s).
421412
422-
ssl_shutdown_timeout is the time in seconds that an SSL server
423-
will wait for the SSL shutdown to finish (defaults to 30s).
424-
425413
start_serving set to True (default) causes the created server
426414
to start accepting connections immediately. When set to False,
427415
the user should await Server.start_serving() or Server.serve_forever()
@@ -432,8 +420,7 @@ async def create_unix_server(
432420
async def connect_accepted_socket(
433421
self, protocol_factory, sock,
434422
*, ssl=None,
435-
ssl_handshake_timeout=None,
436-
ssl_shutdown_timeout=None):
423+
ssl_handshake_timeout=None):
437424
"""Handle an accepted connection.
438425
439426
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
@@ -646,13 +646,11 @@ def _make_ssl_transport(
646646
self, rawsock, protocol, sslcontext, waiter=None,
647647
*, server_side=False, server_hostname=None,
648648
extra=None, server=None,
649-
ssl_handshake_timeout=None,
650-
ssl_shutdown_timeout=None):
649+
ssl_handshake_timeout=None):
651650
ssl_protocol = sslproto.SSLProtocol(
652651
self, protocol, sslcontext, waiter,
653652
server_side, server_hostname,
654-
ssl_handshake_timeout=ssl_handshake_timeout,
655-
ssl_shutdown_timeout=ssl_shutdown_timeout)
653+
ssl_handshake_timeout=ssl_handshake_timeout)
656654
_ProactorSocketTransport(self, rawsock, ssl_protocol,
657655
extra=extra, server=server)
658656
return ssl_protocol._app_transport
@@ -830,8 +828,7 @@ def _write_to_self(self):
830828

831829
def _start_serving(self, protocol_factory, sock,
832830
sslcontext=None, server=None, backlog=100,
833-
ssl_handshake_timeout=None,
834-
ssl_shutdown_timeout=None):
831+
ssl_handshake_timeout=None):
835832

836833
def loop(f=None):
837834
try:
@@ -845,8 +842,7 @@ def loop(f=None):
845842
self._make_ssl_transport(
846843
conn, protocol, sslcontext, server_side=True,
847844
extra={'peername': addr}, server=server,
848-
ssl_handshake_timeout=ssl_handshake_timeout,
849-
ssl_shutdown_timeout=ssl_shutdown_timeout)
845+
ssl_handshake_timeout=ssl_handshake_timeout)
850846
else:
851847
self._make_socket_transport(
852848
conn, protocol,

Lib/asyncio/selector_events.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,11 @@ def _make_ssl_transport(
6565
self, rawsock, protocol, sslcontext, waiter=None,
6666
*, server_side=False, server_hostname=None,
6767
extra=None, server=None,
68-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
69-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT,
70-
):
68+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
7169
ssl_protocol = sslproto.SSLProtocol(
72-
self, protocol, sslcontext, waiter,
73-
server_side, server_hostname,
74-
ssl_handshake_timeout=ssl_handshake_timeout,
75-
ssl_shutdown_timeout=ssl_shutdown_timeout
76-
)
70+
self, protocol, sslcontext, waiter,
71+
server_side, server_hostname,
72+
ssl_handshake_timeout=ssl_handshake_timeout)
7773
_SelectorSocketTransport(self, rawsock, ssl_protocol,
7874
extra=extra, server=server)
7975
return ssl_protocol._app_transport
@@ -145,17 +141,15 @@ def _write_to_self(self):
145141

146142
def _start_serving(self, protocol_factory, sock,
147143
sslcontext=None, server=None, backlog=100,
148-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
149-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT):
144+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
150145
self._add_reader(sock.fileno(), self._accept_connection,
151146
protocol_factory, sock, sslcontext, server, backlog,
152-
ssl_handshake_timeout, ssl_shutdown_timeout)
147+
ssl_handshake_timeout)
153148

154149
def _accept_connection(
155150
self, protocol_factory, sock,
156151
sslcontext=None, server=None, backlog=100,
157-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
158-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT):
152+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
159153
# This method is only called once for each event loop tick where the
160154
# listening socket has triggered an EVENT_READ. There may be multiple
161155
# connections waiting for an .accept() so it is called in a loop.
@@ -186,22 +180,20 @@ def _accept_connection(
186180
self.call_later(constants.ACCEPT_RETRY_DELAY,
187181
self._start_serving,
188182
protocol_factory, sock, sslcontext, server,
189-
backlog, ssl_handshake_timeout,
190-
ssl_shutdown_timeout)
183+
backlog, ssl_handshake_timeout)
191184
else:
192185
raise # The event loop will catch, log and ignore it.
193186
else:
194187
extra = {'peername': addr}
195188
accept = self._accept_connection2(
196189
protocol_factory, conn, extra, sslcontext, server,
197-
ssl_handshake_timeout, ssl_shutdown_timeout)
190+
ssl_handshake_timeout)
198191
self.create_task(accept)
199192

200193
async def _accept_connection2(
201194
self, protocol_factory, conn, extra,
202195
sslcontext=None, server=None,
203-
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT,
204-
ssl_shutdown_timeout=constants.SSL_SHUTDOWN_TIMEOUT):
196+
ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT):
205197
protocol = None
206198
transport = None
207199
try:
@@ -211,8 +203,7 @@ async def _accept_connection2(
211203
transport = self._make_ssl_transport(
212204
conn, protocol, sslcontext, waiter=waiter,
213205
server_side=True, extra=extra, server=server,
214-
ssl_handshake_timeout=ssl_handshake_timeout,
215-
ssl_shutdown_timeout=ssl_shutdown_timeout)
206+
ssl_handshake_timeout=ssl_handshake_timeout)
216207
else:
217208
transport = self._make_socket_transport(
218209
conn, protocol, waiter=waiter, extra=extra,

0 commit comments

Comments
 (0)