Skip to content
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
4 changes: 4 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
---
version: 2

sphinx:
# Path to your Sphinx configuration file.
configuration: docs/conf.py

submodules:
include: all
exclude: []
Expand Down
1 change: 1 addition & 0 deletions CHANGES/10332.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved logging of HTTP protocol errors to include the remote address -- by :user:`bdraco`.
8 changes: 6 additions & 2 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,13 @@ def handle_error(
# or encrypted traffic to an HTTP port. This is expected
# to happen when connected to the public internet so we log
# it at the debug level as to not fill logs with noise.
self.logger.debug("Error handling request", exc_info=exc)
self.logger.debug(
"Error handling request from %s", request.remote, exc_info=exc
)
else:
self.log_exception("Error handling request", exc_info=exc)
self.log_exception(
"Error handling request from %s", request.remote, exc_info=exc
)

# some data already got sent, connection is broken
if request.writer.output_size > 0:
Expand Down
10 changes: 7 additions & 3 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cfgv==3.4.0
# via pre-commit
charset-normalizer==3.4.1
# via requests
cherry-picker==2.4.0
cherry-picker==2.5.0
# via -r requirements/dev.in
click==8.1.8
# via
Expand Down Expand Up @@ -182,7 +182,7 @@ pytest-xdist==3.6.1
# via -r requirements/test.in
python-dateutil==2.9.0.post0
# via freezegun
python-on-whales==0.74.0
python-on-whales==0.75.1
# via
# -r requirements/lint.in
# -r requirements/test.in
Expand Down Expand Up @@ -224,6 +224,10 @@ sphinxcontrib-spelling==8.0.1 ; platform_system != "Windows"
# via -r requirements/doc-spelling.in
sphinxcontrib-towncrier==0.4.0a0
# via -r requirements/doc.in
stamina==24.3.0
# via cherry-picker
tenacity==9.0.0
# via stamina
tomli==2.2.1
# via
# build
Expand Down Expand Up @@ -262,7 +266,7 @@ uvloop==0.21.0 ; platform_system != "Windows"
# -r requirements/lint.in
valkey==6.0.2
# via -r requirements/lint.in
virtualenv==20.29.0
virtualenv==20.29.1
# via pre-commit
wait-for-it==2.3.0
# via -r requirements/test.in
Expand Down
10 changes: 7 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cfgv==3.4.0
# via pre-commit
charset-normalizer==3.4.1
# via requests
cherry-picker==2.4.0
cherry-picker==2.5.0
# via -r requirements/dev.in
click==8.1.8
# via
Expand Down Expand Up @@ -177,7 +177,7 @@ pytest-xdist==3.6.1
# via -r requirements/test.in
python-dateutil==2.9.0.post0
# via freezegun
python-on-whales==0.74.0
python-on-whales==0.75.1
# via
# -r requirements/lint.in
# -r requirements/test.in
Expand Down Expand Up @@ -215,6 +215,10 @@ sphinxcontrib-serializinghtml==2.0.0
# via sphinx
sphinxcontrib-towncrier==0.4.0a0
# via -r requirements/doc.in
stamina==24.3.0
# via cherry-picker
tenacity==9.0.0
# via stamina
tomli==2.2.1
# via
# build
Expand Down Expand Up @@ -253,7 +257,7 @@ uvloop==0.21.0 ; platform_system != "Windows" and implementation_name == "cpytho
# -r requirements/lint.in
valkey==6.0.2
# via -r requirements/lint.in
virtualenv==20.29.0
virtualenv==20.29.1
# via pre-commit
wait-for-it==2.3.0
# via -r requirements/test.in
Expand Down
4 changes: 2 additions & 2 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pytest-mock==3.14.0
# via -r requirements/lint.in
python-dateutil==2.9.0.post0
# via freezegun
python-on-whales==0.74.0
python-on-whales==0.75.1
# via -r requirements/lint.in
pyyaml==6.0.2
# via pre-commit
Expand Down Expand Up @@ -104,5 +104,5 @@ uvloop==0.21.0 ; platform_system != "Windows"
# via -r requirements/lint.in
valkey==6.0.2
# via -r requirements/lint.in
virtualenv==20.29.0
virtualenv==20.29.1
# via pre-commit
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pytest-xdist==3.6.1
# via -r requirements/test.in
python-dateutil==2.9.0.post0
# via freezegun
python-on-whales==0.74.0
python-on-whales==0.75.1
# via -r requirements/test.in
rich==13.9.4
# via pytest-codspeed
Expand Down
2 changes: 1 addition & 1 deletion tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_web___all__(pytester: pytest.Pytester) -> None:
# and even slower under pytest-xdist, especially in CI
_XDIST_WORKER_COUNT * 100 * (1 if _IS_CI_ENV else 1.53)
if _IS_XDIST_RUN
else 265
else 295
),
}
_TARGET_TIMINGS_BY_PYTHON_VERSION["3.13"] = _TARGET_TIMINGS_BY_PYTHON_VERSION["3.12"]
Expand Down
36 changes: 27 additions & 9 deletions tests/test_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
assert txt.startswith("500 Internal Server Error")
assert "Traceback" not in txt

logger.exception.assert_called_with("Error handling request", exc_info=exc)
logger.exception.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_logs_invalid_method_with_loop_debug(
Expand Down Expand Up @@ -96,7 +98,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
# on the first request since the client may
# be probing for TLS/SSL support which is
# expected to fail
logger.debug.assert_called_with("Error handling request", exc_info=exc)
logger.debug.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)
logger.debug.reset_mock()

# Now make another connection to the server
Expand All @@ -110,7 +114,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
# on the first request since the client may
# be probing for TLS/SSL support which is
# expected to fail
logger.debug.assert_called_with("Error handling request", exc_info=exc)
logger.debug.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_logs_invalid_method_without_loop_debug(
Expand Down Expand Up @@ -139,7 +145,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
# on the first request since the client may
# be probing for TLS/SSL support which is
# expected to fail
logger.debug.assert_called_with("Error handling request", exc_info=exc)
logger.debug.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_logs_invalid_method_second_request(
Expand Down Expand Up @@ -170,7 +178,9 @@ async def handler(request: web.BaseRequest) -> web.Response:
# BadHttpMethod should be logged as an exception
# if its not the first request since we know
# that the client already was speaking HTTP
logger.exception.assert_called_with("Error handling request", exc_info=exc)
logger.exception.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_logs_bad_status_line_as_exception(
Expand All @@ -195,7 +205,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
txt = await resp.text()
assert "Traceback (most recent call last):\n" not in txt

logger.exception.assert_called_with("Error handling request", exc_info=exc)
logger.exception.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_handler_timeout(
Expand Down Expand Up @@ -280,7 +292,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
txt = await resp.text()
assert "Traceback (most recent call last):\n" in txt

logger.exception.assert_called_with("Error handling request", exc_info=exc)
logger.exception.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_html_exception(
Expand Down Expand Up @@ -311,7 +325,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
"</body></html>\n"
)

logger.exception.assert_called_with("Error handling request", exc_info=exc)
logger.exception.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_raw_server_html_exception_debug(
Expand Down Expand Up @@ -339,7 +355,9 @@ async def handler(request: web.BaseRequest) -> NoReturn:
"<pre>Traceback (most recent call last):\n"
)

logger.exception.assert_called_with("Error handling request", exc_info=exc)
logger.exception.assert_called_with(
"Error handling request from %s", cli.host, exc_info=exc
)


async def test_handler_cancellation(unused_port_socket: socket.socket) -> None:
Expand Down
Loading