Skip to content

Commit f4662bd

Browse files
committed
fix: keep a request through a proxy alive too
A request that goes through a proxy is served from a separate pool, which the keepalive options never reached. A render behind a proxy is as quiet as any other, so it was still open to the connection being dropped. The pool a proxy uses now gets the same options as a direct one.
1 parent 7efbfbd commit f4662bd

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎codeplain_REST_api.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,19 @@ def keepalive_socket_options():
4747

4848

4949
class KeepaliveAdapter(HTTPAdapter):
50-
"""Opens every connection with keepalive on."""
50+
"""Opens every connection with keepalive on, whether it goes direct or through a proxy."""
5151

5252
def init_poolmanager(self, *args, **kwargs):
5353
kwargs["socket_options"] = keepalive_socket_options()
5454
return super().init_poolmanager(*args, **kwargs)
5555

56+
def proxy_manager_for(self, proxy, **proxy_kwargs):
57+
# A request that goes through a proxy is served from a separate pool, which the
58+
# options above never reach. A render behind a proxy is as quiet as any other and
59+
# needs the same keepalive.
60+
proxy_kwargs["socket_options"] = keepalive_socket_options()
61+
return super().proxy_manager_for(proxy, **proxy_kwargs)
62+
5663

5764
def new_session():
5865
"""A requests session whose connections carry keepalive."""

0 commit comments

Comments
 (0)