Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[3.5] bpo-29743: Closing transport during handshake process leaks socket (#480) #2045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Lib/asyncio/sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,11 @@ def _get_extra_info(self, name, default=None):
def _start_shutdown(self):
if self._in_shutdown:
return
self._in_shutdown = True
self._write_appdata(b'')
if self._in_handshake:
self._abort()
else:
self._in_shutdown = True
self._write_appdata(b'')

def _write_appdata(self, data):
self._write_backlog.append((data, 0))
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def mock_handshake(callback):
sslpipe.do_handshake.side_effect = mock_handshake
with mock.patch('asyncio.sslproto._SSLPipe', return_value=sslpipe):
ssl_proto.connection_made(transport)
return transport

def test_cancel_handshake(self):
# Python issue #23197: cancelling a handshake must not raise an
Expand Down Expand Up @@ -95,6 +96,20 @@ 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)
ssl_proto = self.ssl_protocol(waiter)

def do_handshake(callback):
return []

transport = self.connection_made(ssl_proto)
test_utils.run_briefly(self.loop)

ssl_proto._app_transport.close()
self.assertTrue(transport.abort.called)

def test_get_extra_info_on_closed_connection(self):
waiter = asyncio.Future(loop=self.loop)
ssl_proto = self.ssl_protocol(waiter)
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Extension Modules
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