Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable keep-alive when working with proxy #3070

Merged
merged 2 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES/3070.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Many HTTP proxies has buggy keepalive support.
Let's not reuse connection but close it after processing every response.
3 changes: 3 additions & 0 deletions aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asvetlov do you have exact references which proxies do not support keepalive correctly ?

Rejecting keepalive will enlarge latencies, and make problems with frequent requests due to TIME_WAIT and inability to reuse TCP ports.

# 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():
Expand Down