From 04e2a2fa41c4a479a747ff070d53af9af1e27db9 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Fri, 9 Feb 2018 15:45:15 +0200 Subject: [PATCH] Fix #2444: Properly handle BaseException when re-raising --- aiohttp/client.py | 6 +++--- aiohttp/client_reqrep.py | 2 +- aiohttp/connector.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/aiohttp/client.py b/aiohttp/client.py index b7422ada30b..93eff65e604 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -329,7 +329,7 @@ async def _request(self, method, url, *, resp = req.send(conn) try: await resp.start(conn, read_until_eof) - except Exception: + except BaseException: resp.close() conn.close() raise @@ -425,7 +425,7 @@ async def _request(self, method, url, *, ) return resp - except Exception as e: + except BaseException as e: # cleanup timer tm.close() if handle: @@ -611,7 +611,7 @@ async def _ws_connect(self, url, *, writer = WebSocketWriter( proto, transport, use_mask=True, compress=compress, notakeover=notakeover) - except Exception: + except BaseException: resp.close() raise else: diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index 65ddd66e376..5c169c07e87 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -796,7 +796,7 @@ async def read(self): if self._content is None: try: self._content = await self.content.read() - except Exception: + except BaseException: self.close() raise diff --git a/aiohttp/connector.py b/aiohttp/connector.py index acb898f7cd1..2d9108b0a47 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -420,7 +420,7 @@ async def connect(self, req, traces=None): if self._closed: proto.close() raise ClientConnectionError("Connector is closed.") - except Exception: + except BaseException: # signal to waiter if key in self._waiters: for waiter in self._waiters[key]: @@ -710,7 +710,7 @@ async def _resolve_host(self, host, port, traces=None): self._cached_hosts.add(key, addrs) self._throttle_dns_events[key].set() - except Exception as e: + except BaseException as e: # any DNS exception, independently of the implementation # is set for the waiters to raise the same exception. self._throttle_dns_events[key].set(exc=e) @@ -896,7 +896,7 @@ async def _create_proxy_connection(self, req, traces=None): proxy_resp = proxy_req.send(conn) try: resp = await proxy_resp.start(conn, True) - except Exception: + except BaseException: proxy_resp.close() conn.close() raise