8000 bpo-29742: asyncio get_extra_info() throws exception (#525) · python/cpython@2b27e2e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b27e2e

Browse files
fafhrd911st1
authored andcommitted
bpo-29742: asyncio get_extra_info() throws exception (#525)
1 parent 783d0c1 commit 2b27e2e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Lib/asyncio/sslproto.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,10 @@ def eof_received(self):
543543
def _get_extra_info(self, name, default=None):
544544
if name in self._extra:
545545
return self._extra[name]
546-
else:
546+
elif self._transport is not None:
547547
return self._transport.get_extra_info(name, default)
548+
else:
549+
return default
548550

549551
def _start_shutdown(self):
550552
if self._in_shutdown:

Lib/test/test_asyncio/test_sslproto.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,17 @@ def test_connection_lost(self):
9595
test_utils.run_briefly(self.loop)
9696
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)
9797

98+
def test_get_extra_info_on_closed_connection(self):
99+
waiter = asyncio.Future(loop=self.loop)
100+
ssl_proto = self.ssl_protocol(waiter)
101+
self.assertIsNone(ssl_proto._get_extra_info('socket'))
102+
default = object()
103+
self.assertIs(ssl_proto._get_extra_info('socket', default), default)
104+
self.connection_made(ssl_proto)
105+
self.assertIsNotNone(ssl_proto._get_extra_info('socket'))
106+
ssl_proto.connection_lost(None)
107+
self.assertIsNone(ssl_proto._get_extra_info('socket'))
108+
109+
98110
if __name__ == '__main__':
99111
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ Library
335335
- bpo-28518: Start a transaction implicitly before a DML statement.
336336
Patch by Aviv Palivoda.
337337

338+
- bpo-29742: get_extra_info() raises exception if get called on closed ssl transport.
339+
Patch by Nikolay Kim.
340+
338341
- Issue #16285: urrlib.parse.quote is now based on RFC 3986 and hence includes
339342
'~' in the set of characters that is not quoted by default. Patch by
340343
Christian Theune and Ratnadeep Debnath.

0 commit comments

Comments
 (0)
0