Skip to content

Commit a16607f

Browse files
committed
bpo-31632: fix set_protocol() in _SSLProtocolTransport (#3817)
1 parent d780b2d commit a16607f

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

Lib/asyncio/sslproto.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,21 @@ def feed_appdata(self, data, offset=0):
293293
class _SSLProtocolTransport(transports._FlowControlMixin,
294294
transports.Transport):
295295

296-
def __init__(self, loop, ssl_protocol, app_protocol):
296+
def __init__(self, loop, ssl_protocol):
297297
self._loop = loop
298298
# SSLProtocol instance
299299
self._ssl_protocol = ssl_protocol
300-
self._app_protocol = app_protocol
301300
self._closed = False
302301

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

307306
def set_protocol(self, protocol):
308-
self._app_protocol = protocol
307+
self._ssl_protocol._app_protocol = protocol
309308

310309
def get_protocol(self):
311-
return self._app_protocol
310+
return self._ssl_protocol._app_protocol
312311

313312
def is_closing(self):
314313
return self._closed
@@ -431,8 +430,7 @@ def __init__(self, loop, app_protocol, sslcontext, waiter,
431430
self._waiter = waiter
432431
self._loop = loop
433432
self._app_protocol = app_protocol
434-
self._app_transport = _SSLProtocolTransport(self._loop,
435-
self, self._app_protocol)
433+
self._app_transport = _SSLProtocolTransport(self._loop, self)
436434
# _SSLPipe instance (None until the connection is made)
437435
self._sslpipe = None
438436
self._session_established = False

Lib/test/test_asyncio/test_sslproto.py

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ def test_get_extra_info_on_closed_connection(self):
121121
ssl_proto.connection_lost(None)
122122
self.assertIsNone(ssl_proto._get_extra_info('socket'))
123123

124+
def test_set_new_app_protocol(self):
125+
waiter = asyncio.Future(loop=self.loop)
126+
ssl_proto = self.ssl_protocol(waiter)
127+
new_app_proto = asyncio.Protocol()
128+
ssl_proto._app_transport.set_protocol(new_app_proto)
129+
self.assertIs(ssl_proto._app_transport.get_protocol(), new_app_proto)
130+
self.assertIs(ssl_proto._app_protocol, new_app_proto)
131+
124132

125133
if __name__ == '__main__':
126134
unittest.main()

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ Vladimir Kushnir
856856
Erno Kuusela
857857
Ross Lagerwall
858858
Cameron Laird
859+
Loïc Lajeanne
859860
David Lam
860861
Thomas Lamb
861862
Valerie Lambert
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix method set_protocol() of class _SSLProtocolTransport in asyncio module.
2+
This method was previously modifying a wrong reference to the protocol.

0 commit comments

Comments
 (0)