From b8830bcb55a86a341083e87f874256ee82536b1a Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 11 Jun 2018 16:48:12 +0300 Subject: [PATCH 1/2] Disable keep-alive when working with proxy --- aiohttp/client_proto.py | 3 +++ aiohttp/connector.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index b42a769c704..00d98ebfff0 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -45,6 +45,9 @@ def should_close(self): self._payload_parser is not None or len(self) or self._tail) + def force_close(self): + self._should_close = True + def close(self): transport = self.transport if transport is not None: diff --git a/aiohttp/connector.py b/aiohttp/connector.py index ab4e8feb18a..24507c16027 100644 --- a/aiohttp/connector.py +++ b/aiohttp/connector.py @@ -895,6 +895,11 @@ async def _create_proxy_connection(self, req, traces, timeout): transport, proto = await self._create_direct_connection( proxy_req, [], timeout, client_error=ClientProxyConnectionError) + # Many HTTP proxies has buggy keepalive support. Let's not + # reuse connection but close it after processing every + # response. + proto.force_close() + auth = proxy_req.headers.pop(hdrs.AUTHORIZATION, None) if auth is not None: if not req.is_ssl(): From 3eba4b320722892a46485fac8ae0ac190238f1e0 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 11 Jun 2018 16:49:47 +0300 Subject: [PATCH 2/2] Add changenote --- CHANGES/3070.bugfix | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 CHANGES/3070.bugfix diff --git a/CHANGES/3070.bugfix b/CHANGES/3070.bugfix new file mode 100644 index 00000000000..185a7328c72 --- /dev/null +++ b/CHANGES/3070.bugfix @@ -0,0 +1,2 @@ +Many HTTP proxies has buggy keepalive support. +Let's not reuse connection but close it after processing every response. \ No newline at end of file