File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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__(
192192 ):
193193 super ().__init__ (loop )
194194
195+ # _request_count is the number of requests processed with the same connection.
195196 self ._request_count = 0
196197 self ._keepalive = False
197198 self ._current_request : Optional [BaseRequest ] = None
@@ -688,11 +689,7 @@ def handle_error(
688689 Returns HTTP response with specific status code. Logs additional
689690 information. It always closes current connection.
690691 """
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 ):
696693 # BadHttpMethod is common when a client sends non-HTTP
697694 # or encrypted traffic to an HTTP port. This is expected
698695 # 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__(
2525 self ._loop = loop or asyncio .get_running_loop ()
2626 self ._connections : Dict [RequestHandler , asyncio .Transport ] = {}
2727 self ._kwargs = kwargs
28+ # requests_count is the number of requests being processed by the server
29+ # for the lifetime of the server.
2830 self .requests_count = 0
2931 self .request_handler = handler
3032 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:
8686 # be probing for TLS/SSL support which is
8787 # expected to fail
8888 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 )
89103
90104
91105async def test_raw_server_logs_invalid_method_without_loop_debug (
You can’t perform that action at this time.
0 commit comments