File tree Expand file tree Collapse file tree 5 files changed +20
-5
lines changed Expand file tree Collapse file tree 5 files changed +20
-5
lines changed Original file line number Diff line number Diff line change
1
+ 10076.bugfix.rst
Original file line number Diff line number Diff line change
1
+ Fixed invalid method logging unexpected being logged at exception level on subsequent connections -- by :user: `bdraco `.
Original file line number Diff line number Diff line change @@ -192,6 +192,7 @@ def __init__(
192
192
):
193
193
super ().__init__ (loop )
194
194
195
+ # _request_count is the number of requests processed with the same connection.
195
196
self ._request_count = 0
196
197
self ._keepalive = False
197
198
self ._current_request : Optional [BaseRequest ] = None
@@ -688,11 +689,7 @@ def handle_error(
688
689
Returns HTTP response with specific status code. Logs additional
689
690
information. It always closes current connection.
690
691
"""
691
- if (
692
- self ._manager
693
- and self ._manager .requests_count == 1
694
- and isinstance (exc , BadHttpMethod )
695
- ):
692
+ if self ._request_count == 1 and isinstance (exc , BadHttpMethod ):
696
693
# BadHttpMethod is common when a client sends non-HTTP
697
694
# or encrypted traffic to an HTTP port. This is expected
698
695
# to happen when connected to the public internet so we log
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ def __init__(
25
25
self ._loop = loop or asyncio .get_running_loop ()
26
26
self ._connections : Dict [RequestHandler , asyncio .Transport ] = {}
27
27
self ._kwargs = kwargs
28
+ # requests_count is the number of requests being processed by the server
29
+ # for the lifetime of the server.
28
30
self .requests_count = 0
29
31
self .request_handler = handler
30
32
self .request_factory = request_factory or self ._make_request
Original file line number Diff line number Diff line change @@ -86,6 +86,20 @@ async def handler(request: web.BaseRequest) -> NoReturn:
86
86
# be probing for TLS/SSL support which is
87
87
# expected to fail
88
88
logger .debug .assert_called_with ("Error handling request" , exc_info = exc )
89
+ logger .debug .reset_mock ()
90
+
91
+ # Now make another connection to the server
92
+ # to make sure that the exception is logged
93
+ # at debug on a second fresh connection
94
+ cli2 = await aiohttp_client (server )
95
+ resp = await cli2 .get ("/path/to" )
96
+ assert resp .status == 500
97
+ assert resp .headers ["Content-Type" ].startswith ("text/plain" )
98
+ # BadHttpMethod should be logged as debug
99
+ # on the first request since the client may
100
+ # be probing for TLS/SSL support which is
101
+ # expected to fail
102
+ logger .debug .assert_called_with ("Error handling request" , exc_info = exc )
89
103
90
104
91
105
async def test_raw_server_logs_invalid_method_without_loop_debug (
You can’t perform that action at this time.
0 commit comments