Skip to content

Commit 9c23b17

Browse files
miss-islington1st1
authored andcommitted
bpo-31632: fix set_protocol() in _SSLProtocolTransport (GH-3817) (GH-3817) (#4052)
(cherry picked from commit ea2ef5d)
1 parent 4d9a8f2 commit 9c23b17

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
@@ -294,22 +294,21 @@ def feed_appdata(self, data, offset=0):
294294
class _SSLProtocolTransport(transports._FlowControlMixin,
295295
transports.Transport):
296296

297-
def __init__(self, loop, ssl_protocol, app_protocol):
297+
def __init__(self, loop, ssl_protocol):
298298
self._loop = loop
299299
# SSLProtocol instance
300300
self._ssl_protocol = ssl_protocol
301-
self._app_protocol = app_protocol
302301
self._closed = False
303302

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

308307
def set_protocol(self, protocol):
309-
self._app_protocol = protocol
308+
self._ssl_protocol._app_protocol = protocol
310309

311310
def get_protocol(self):
312-
return self._app_protocol
311+
return self._ssl_protocol._app_protocol
313312

314313
def is_closing(self):
315314
return self._closed
@@ -436,8 +435,7 @@ def __init__(self, loop, app_protocol, sslcontext, waiter,
436435
self._waiter = waiter
437436
self._loop = loop
438437
self._app_protocol = app_protocol
439-
self._app_transport = _SSLProtocolTransport(self._loop,
440-
self, self._app_protocol)
438+
self._app_transport = _SSLProtocolTransport(self._loop, self)
441439
# _SSLPipe instance (None until the connection is made)
442440
self._sslpipe = None
443441
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
@@ -849,6 +849,7 @@ Vladimir Kushnir
849849
Erno Kuusela
850850
Ross Lagerwall
851851
Cameron Laird
852+
Loïc Lajeanne
852853
David Lam
853854
Thomas Lamb
854855
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)