Skip to content

Commit 71ada0b

Browse files
committed
Revert "[3.5] bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (GH-409) (#2063)"
This reverts commit 1395c58.
1 parent d24c828 commit 71ada0b

File tree

3 files changed

+1
-61
lines changed

3 files changed

+1
-61
lines changed

Lib/asyncio/sslproto.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from . import base_events
99
from . import compat
10-
from . import futures
1110
from . import protocols
1211
from . import transports
1312
from .log import logger
@@ -412,7 +411,7 @@ class SSLProtocol(protocols.Protocol):
412411

413412
def __init__(self, loop, app_protocol, sslcontext, waiter,
414413
server_side=False, server_hostname=None,
415-
call_connection_made=True, shutdown_timeout=5.0):
414+
call_connection_made=True):
416415
if ssl is None:
417416
raise RuntimeError('stdlib ssl module not available')
418417

@@ -443,8 +442,6 @@ def __init__(self, loop, app_protocol, sslcontext, waiter,
443442
self._session_established = False
444443
self._in_handshake = False
445444
self._in_shutdown = False
446-
self._shutdown_timeout = shutdown_timeout
447-
self._shutdown_timeout_handle = None
448445
# transport, ex: SelectorSocketTransport
449446
self._transport = None
450447
self._call_connection_made = call_connection_made
@@ -559,15 +556,6 @@ def _start_shutdown(self):
559556
self._in_shutdown = True
560557
self._write_appdata(b'')
561558

562-
if self._shutdown_timeout is not None:
563-
self._shutdown_timeout_handle = self._loop.call_later(
564-
self._shutdown_timeout, self._on_shutdown_timeout)
565-
566-
def _on_shutdown_timeout(self):
567-
if self._transport is not None:
568-
self._fatal_error(
569-
futures.TimeoutError(), 'Can not complete shitdown operation')
570-
571559
def _write_appdata(self, data):
572560
self._write_backlog.append((data, 0))
573561
self._write_buffer_size += len(data)
@@ -695,22 +683,12 @@ def _fatal_error(self, exc, message='Fatal error on transport'):
695683
})
696684
if self._transport:
697685
self._transport._force_close(exc)
698-
self._transport = None
699-
700-
if self._shutdown_timeout_handle is not None:
701-
self._shutdown_timeout_handle.cancel()
702-
self._shutdown_timeout_handle = None
703686

704687
def _finalize(self):
705688
self._sslpipe = None
706689

707690
if self._transport is not None:
708691
self._transport.close()
709-
self._transport = None
710-
711-
if self._shutdown_timeout_handle is not None:
712-
self._shutdown_timeout_handle.cancel()
713-
self._shutdown_timeout_handle = None
714692

715693
def _abort(self):
716694
try:

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -96,40 +96,6 @@ def test_connection_lost(self):
9696
test_utils.run_briefly(self.loop)
9797
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)
9898

99-
def test_close_abort(self):
100-
# From issue #bpo-29406
101-
# abort connection if server does not complete shutdown procedure
102-
ssl_proto = self.ssl_protocol()
103-
transport = self.connection_made(ssl_proto)
104-
ssl_proto._on_handshake_complete(None)
105-
ssl_proto._start_shutdown()
106-
self.assertIsNotNone(ssl_proto._shutdown_timeout_handle)
107-
108-
exc_handler = mock.Mock()
109-
self.loop.set_exception_handler(exc_handler)
110-
ssl_proto._shutdown_timeout_handle._run()
111-
112-
exc_handler.assert_called_with(
113-
self.loop, {'message': 'Can not complete shitdown operation',
114-
'exception': mock.ANY,
115-
'transport': transport,
116-
'protocol': ssl_proto}
117-
)
118-
self.assertIsNone(ssl_proto._shutdown_timeout_handle)
119-
120-
def test_close(self):
121-
# From issue #bpo-29406
122-
# abort connection if server does not complete shutdown procedure
123-
ssl_proto = self.ssl_protocol()
124-
transport = self.connection_made(ssl_proto)
125-
ssl_proto._on_handshake_complete(None)
126-
ssl_proto._start_shutdown()
127-
self.assertIsNotNone(ssl_proto._shutdown_timeout_handle)
128-
129-
ssl_proto._finalize()
130-
self.assertIsNone(ssl_proto._transport)
131-
self.assertIsNone(ssl_proto._shutdown_timeout_handle)
132-
13399
def test_close_during_handshake(self):
134100
# bpo-29743 Closing transport during handshake process leaks socket
135101
waiter = asyncio.Future(loop=self.loop)

Misc/NEWS

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ Library
6969
- bpo-29743: Closing transport during handshake process leaks open socket.
7070
Patch by Nikolay Kim
7171

72-
- bpo-29406: asyncio SSL contexts leak sockets after calling close with
73-
certain servers.
74-
Patch by Nikolay Kim
75-
7672
- bpo-27585: Fix waiter cancellation in asyncio.Lock.
7773
Patch by Mathieu Sornay.
7874

0 commit comments

Comments
 (0)