◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
25 changes: 24 additions & 1 deletion Lib/asyncio/sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
ssl = None

from . import base_events
from . import protocols
from . import transports
from .log import logger
Expand Down Expand Up @@ -407,7 +409,7 @@ class SSLProtocol(protocols.Protocol):

def __init__(self, loop, app_protocol, sslcontext, waiter,
server_side=False, server_hostname=None,
call_connection_made=True):
if ssl is None:
raise RuntimeError('stdlib ssl module not available')

Expand Down Expand Up @@ -438,6 +440,8 @@ def __init__(self, loop, app_protocol, sslcontext, waiter,
self._session_established = False
self._in_handshake = False
self._in_shutdown = False
# transport, ex: SelectorSocketTransport
self._transport = None
self._call_connection_made = call_connection_made
Expand Down @@ -552,6 +556,15 @@ def _start_shutdown(self):
self._in_shutdown = True
self._write_appdata(b'')

def _write_appdata(self, data):
self._write_backlog.append((data, 0))
self._write_buffer_size += len(data)
Expand Down Expand Up @@ -679,12 +692,22 @@ def _fatal_error(self, exc, message='Fatal error on transport'):
})
if self._transport:
self._transport._force_close(exc)

def _finalize(self):
self._sslpipe = None

if self._transport is not None:
self._transport.close()

def _abort(self):
try:
Expand Down
34 changes: 34 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,40 @@ def test_connection_lost(self):
test_utils.run_briefly(self.loop)
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)

def test_close_during_handshake(self):
# bpo-29743 Closing transport during handshake process leaks socket
waiter = asyncio.Future(loop=self.loop)
4 changes: 4 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ Library
- bpo-29743: Closing transport during handshake process leaks open socket.
Patch by Nikolay Kim

- bpo-27585: Fix waiter cancellation in asyncio.Lock.
Patch by Mathieu Sornay.

Expand Down
Toggle all file notes Toggle all file annotations