]> granicus.if.org Git - python/commitdiff
bpo-29742: asyncio get_extra_info() throws exception (#525)
authorNikolay Kim <fafhrd91@gmail.com>
Sun, 12 Mar 2017 19:23:30 +0000 (12:23 -0700)
committerYury Selivanov <yselivanov@gmail.com>
Sun, 12 Mar 2017 19:23:30 +0000 (15:23 -0400)
Lib/asyncio/sslproto.py
Lib/test/test_asyncio/test_sslproto.py
Misc/NEWS

index 7ad28d6aa0089a67a8892558b983ebae1de7b7d1..ab7ff0bf93d076ad93524357990332b603c2724a 100644 (file)
@@ -543,8 +543,10 @@ class SSLProtocol(protocols.Protocol):
     def _get_extra_info(self, name, default=None):
         if name in self._extra:
             return self._extra[name]
-        else:
+        elif self._transport is not None:
             return self._transport.get_extra_info(name, default)
+        else:
+            return default
 
     def _start_shutdown(self):
         if self._in_shutdown:
index 59ff0f6967e5b5bbec3232a160d5c26d28986b79..f1771c5561afea819c3fdc6590efbc1d1d84d3fb 100644 (file)
@@ -95,5 +95,17 @@ class SslProtoHandshakeTests(test_utils.TestCase):
         test_utils.run_briefly(self.loop)
         self.assertIsInstance(waiter.exception(), ConnectionAbortedError)
 
+    def test_get_extra_info_on_closed_connection(self):
+        waiter = asyncio.Future(loop=self.loop)
+        ssl_proto = self.ssl_protocol(waiter)
+        self.assertIsNone(ssl_proto._get_extra_info('socket'))
+        default = object()
+        self.assertIs(ssl_proto._get_extra_info('socket', default), default)
+        self.connection_made(ssl_proto)
+        self.assertIsNotNone(ssl_proto._get_extra_info('socket'))
+        ssl_proto.connection_lost(None)
+        self.assertIsNone(ssl_proto._get_extra_info('socket'))
+
+
 if __name__ == '__main__':
     unittest.main()
index d4f0f25a292242593d073b130dd0cac13b87a892..72404b3ac2413d6591e61553c59974a74d5c027c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -335,6 +335,9 @@ Library
 - bpo-28518: Start a transaction implicitly before a DML statement.
   Patch by Aviv Palivoda.
 
+- bpo-29742: get_extra_info() raises exception if get called on closed ssl transport.
+  Patch by Nikolay Kim.
+
 - Issue #16285: urrlib.parse.quote is now based on RFC 3986 and hence includes
   '~' in the set of characters that is not quoted by default. Patch by
   Christian Theune and Ratnadeep Debnath.