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

Increase default keepalive_timeout server-side. (#9285) #9293

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
1 change: 1 addition & 0 deletions CHANGES/9285.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed web ``keepalive_timeout`` default to around an hour in order to reduce race conditions on reverse proxies -- by :user:`Dreamsorcerer`.
3 changes: 2 additions & 1 deletion aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def __init__(
manager: "Server",
*,
loop: asyncio.AbstractEventLoop,
keepalive_timeout: float = 75.0, # NGINX default is 75 secs
# Default should be high enough that it's likely longer than a reverse proxy.
keepalive_timeout: float = 3630,
tcp_keepalive: bool = True,
logger: Logger = server_logger,
access_log_class: Type[AbstractAccessLogger] = AccessLogger,
Expand Down
12 changes: 10 additions & 2 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,9 @@ application on specific TCP or Unix socket, e.g.::

:param bool tcp_keepalive: Enable TCP Keep-Alive. Default: ``True``.
:param int keepalive_timeout: Number of seconds before closing Keep-Alive
connection. Default: ``75`` seconds (NGINX's default value).
connection. Default: ``3630`` seconds (when deployed behind a reverse proxy
it's important for this value to be higher than the proxy's timeout. To avoid
race conditions we always want the proxy to close the connection).
:param logger: Custom logger object. Default:
:data:`aiohttp.log.server_logger`.
:param access_log: Custom logging object. Default:
Expand Down Expand Up @@ -2985,7 +2987,7 @@ Utilities

.. function:: run_app(app, *, host=None, port=None, path=None, \
sock=None, shutdown_timeout=60.0, \
keepalive_timeout=75.0, \
keepalive_timeout=3630, \
ssl_context=None, print=print, backlog=128, \
access_log_class=aiohttp.helpers.AccessLogger, \
access_log_format=aiohttp.helpers.AccessLogger.LOG_FORMAT, \
Expand Down Expand Up @@ -3052,6 +3054,12 @@ Utilities
closed after a HTTP request. The delay
allows for reuse of a TCP connection.

When deployed behind a reverse proxy
it's important for this value to be
higher than the proxy's timeout. To avoid
race conditions, we always want the proxy
to handle connection closing.

.. versionadded:: 3.8

:param ssl_context: :class:`ssl.SSLContext` for HTTPS server,
Expand Down
Loading