diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-01-14 15:56:20 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-01-14 15:56:20 (GMT) |
commit | 177e9f0855ca398bf208a7466ed288e2ae22f6d5 (patch) | |
tree | 27c994b28ebad69a451db7937c7fed06e37ff37a /Lib/asyncio | |
parent | f651a604075c2dc9a2d7f3d3bd74da374ff8a696 (diff) | |
download | cpython-177e9f0855ca398bf208a7466ed288e2ae22f6d5.zip cpython-177e9f0855ca398bf208a7466ed288e2ae22f6d5.tar.gz cpython-177e9f0855ca398bf208a7466ed288e2ae22f6d5.tar.bz2 |
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
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/selector_events.py | 2 | ||||
-rw-r--r-- | Lib/asyncio/sslproto.py | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index b2f29c7..ca86264 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -750,7 +750,7 @@ class _SelectorSslTransport(_SelectorTransport): self._loop.remove_reader(self._sock_fd) self._loop.remove_writer(self._sock_fd) self._sock.close() - if self._waiter is not None: + if self._waiter is not None and not self._waiter.cancelled(): self._waiter.set_exception(exc) if isinstance(exc, Exception): return diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 987c158..541e252 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: |