From 177e9f0855ca398bf208a7466ed288e2ae22f6d5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 14 Jan 2015 16:56:20 +0100 Subject: Issue #23197, asyncio: On SSL handshake failure, check if the waiter is cancelled before setting its exception. * Add unit tests for this case. * Cleanup also sslproto.py --- Lib/asyncio/sslproto.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Lib/asyncio/sslproto.py') diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 987c158ee73..541e252774e 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -530,10 +530,11 @@ class SSLProtocol(protocols.Protocol): self._in_handshake = False sslobj = self._sslpipe.ssl_object - peercert = None if handshake_exc else sslobj.getpeercert() try: if handshake_exc is not None: raise handshake_exc + + peercert = sslobj.getpeercert() if not hasattr(self._sslcontext, 'check_hostname'): # Verify hostname if requested, Python 3.4+ uses check_hostname # and checks the hostname in do_handshake() @@ -551,7 +552,7 @@ class SSLProtocol(protocols.Protocol): self, exc_info=True) self._transport.close() if isinstance(exc, Exception): - if self._waiter is not None: + if self._waiter is not None and not self._waiter.cancelled(): self._waiter.set_exception(exc) return else: -- cgit v1.2.3