summaryrefslogtreecommitdiff
path: root/Lib/asyncio/sslproto.py
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2019-05-27 14:45:12 +0200
committerGitHub <noreply@github.com>2019-05-27 14:45:12 +0200
commit431b540bf79f0982559b1b0e420b1b085f667bb7 (patch)
tree2e7027339ce786cc90e04cba1b03c71ecf38dfda /Lib/asyncio/sslproto.py
parent16cefb0bc7b05c08caf08525398ff178c35dece4 (diff)
downloadcpython-git-431b540bf79f0982559b1b0e420b1b085f667bb7.tar.gz
bpo-32528: Make asyncio.CancelledError a BaseException. (GH-13528)
This will address the common mistake many asyncio users make: an "except Exception" clause breaking Tasks cancellation. In addition to this change, we stop inheriting asyncio.TimeoutError and asyncio.InvalidStateError from their concurrent.futures.* counterparts. There's no point for these exceptions to share the inheritance chain. In 3.9 we'll focus on implementing supervisors and cancel scopes, which should allow better handling of all exceptions, including SystemExit and KeyboardInterrupt
Diffstat (limited to 'Lib/asyncio/sslproto.py')
-rw-r--r--Lib/asyncio/sslproto.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 97a6fc66a9..8546985fe6 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -527,7 +527,9 @@ class SSLProtocol(protocols.Protocol):
try:
ssldata, appdata = self._sslpipe.feed_ssldata(data)
- except Exception as e:
+ except (SystemExit, KeyboardInterrupt):
+ raise
+ except BaseException as e:
self._fatal_error(e, 'SSL error in data received')
return
@@ -542,7 +544,9 @@ class SSLProtocol(protocols.Protocol):
self._app_protocol, chunk)
else:
self._app_protocol.data_received(chunk)
- except Exception as ex:
+ except (SystemExit, KeyboardInterrupt):
+ raise
+ except BaseException as ex:
self._fatal_error(
ex, 'application protocol failed to receive SSL data')
return
@@ -628,7 +632,9 @@ class SSLProtocol(protocols.Protocol):
raise handshake_exc
peercert = sslobj.getpeercert()
- except Exception as exc:
+ except (SystemExit, KeyboardInterrupt):
+ raise
+ except BaseException as exc:
if isinstance(exc, ssl.CertificateError):
msg = 'SSL handshake failed on verifying the certificate'
else:
@@ -691,7 +697,9 @@ class SSLProtocol(protocols.Protocol):
# delete it and reduce the outstanding buffer size.
del self._write_backlog[0]
self._write_buffer_size -= len(data)
- except Exception as exc:
+ except (SystemExit, KeyboardInterrupt):
+ raise
+ except BaseException as exc:
if self._in_handshake:
# Exceptions will be re-raised in _on_handshake_complete.
self._on_handshake_complete(exc)