Skip to content

Commit 83d30bd

Browse files
authored
Revert "[3.6] bpo-29406: asyncio SSL contexts leak sockets after calling close with certain servers (GH-409) (#2062)" (#2112)
This reverts commit 6e14fd2.
1 parent 176f2eb commit 83d30bd

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
@@ -413,7 +412,7 @@ class SSLProtocol(protocols.Protocol):
413412

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

@@ -444,8 +443,6 @@ def __init__(self, loop, app_protocol, sslcontext, waiter,
444443
self._session_established = False
445444
self._in_handshake = False
446445
self._in_shutdown = False
447-
self._shutdown_timeout = shutdown_timeout
448-
self._shutdown_timeout_handle = None
449446
# transport, ex: SelectorSocketTransport
450447
self._transport = None
451448
self._call_connection_made = call_connection_made
@@ -560,15 +557,6 @@ def _start_shutdown(self):
560557
self._in_shutdown = True
561558
self._write_appdata(b'')
562559

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

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

708691
if self._transport is not None:
709692
self._transport.close()
710-
self._transport = None
711-
712-
if self._shutdown_timeout_handle is not None:
713-
self._shutdown_timeout_handle.cancel()
714-
self._shutdown_timeout_handle = None
715693

716694
def _abort(self):
717695
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
@@ -56,10 +56,6 @@ Library
5656
support for ContextManager on all versions. Original PRs by Jelle Zijlstra
5757
and Ivan Levkivskyi
5858

59-
- bpo-29406: asyncio SSL contexts leak sockets after calling close with
60-
certain servers.
61-
Patch by Nikolay Kim
62-
6359
- bpo-29870: Fix ssl sockets leaks when connection is aborted in asyncio/ssl
6460
implementation. Patch by Michaël Sghaïer.
6561

0 commit comments

Comments
 (0)