Skip to content
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

bpo-31632: (asyncio) remove local reference to app protocol in _SSLProtocolTransport #3817

Merged
merged 1 commit into from
Oct 19, 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
10 changes: 4 additions & 6 deletions Lib/asyncio/sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,21 @@ def feed_appdata(self, data, offset=0):
class _SSLProtocolTransport(transports._FlowControlMixin,
transports.Transport):

def __init__(self, loop, ssl_protocol, app_protocol):
def __init__(self, loop, ssl_protocol):
self._loop = loop
# SSLProtocol instance
self._ssl_protocol = ssl_protocol
self._app_protocol = app_protocol
self._closed = False

def get_extra_info(self, name, default=None):
"""Get optional transport information."""
return self._ssl_protocol._get_extra_info(name, default)

def set_protocol(self, protocol):
self._app_protocol = protocol
self._ssl_protocol._app_protocol = protocol

def get_protocol(self):
return self._app_protocol
return self._ssl_protocol._app_protocol

def is_closing(self):
return self._closed
Expand Down Expand Up @@ -431,8 +430,7 @@ def __init__(self, loop, app_protocol, sslcontext, waiter,
self._waiter = waiter
self._loop = loop
self._app_protocol = app_protocol
self._app_transport = _SSLProtocolTransport(self._loop,
self, self._app_protocol)
self._app_transport = _SSLProtocolTransport(self._loop, self)
# _SSLPipe instance (None until the connection is made)
self._sslpipe = None
self._session_established = False
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ def test_get_extra_info_on_closed_connection(self):
ssl_proto.connection_lost(None)
self.assertIsNone(ssl_proto._get_extra_info('socket'))

def test_set_new_app_protocol(self):
waiter = asyncio.Future(loop=self.loop)
ssl_proto = self.ssl_protocol(waiter)
new_app_proto = asyncio.Protocol()
ssl_proto._app_transport.set_protocol(new_app_proto)
self.assertIs(ssl_proto._app_transport.get_protocol(), new_app_proto)
self.assertIs(ssl_proto._app_protocol, new_app_proto)


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ Vladimir Kushnir
Erno Kuusela
Ross Lagerwall
Cameron Laird
Loïc Lajeanne
David Lam
Thomas Lamb
Valerie Lambert
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix method set_protocol() of class _SSLProtocolTransport in asyncio module.
This method was previously modifying a wrong reference to the protocol.