diff --git a/CHANGES/3414.bugfix b/CHANGES/3414.bugfix new file mode 100644 index 00000000000..d20a62ebf86 --- /dev/null +++ b/CHANGES/3414.bugfix @@ -0,0 +1,2 @@ +Fix `asyncio.TimeoutError` stack trace not logged, when it is caught +in the handler. diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 538b0d0f834..5cfd24d5a28 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -172,6 +172,7 @@ Paulius Šileikis Paulus Schoutsen Pavel Kamaev Pavel Polyakov +Pawel Kowalski Pawel Miech Pepe Osca Philipp A. diff --git a/aiohttp/web_protocol.py b/aiohttp/web_protocol.py index bd98c4a7c4a..9399cf86b9a 100644 --- a/aiohttp/web_protocol.py +++ b/aiohttp/web_protocol.py @@ -408,8 +408,8 @@ async def start(self) -> None: except asyncio.CancelledError: self.log_debug('Ignored premature client disconnection') break - except asyncio.TimeoutError: - self.log_debug('Request handler timed out.') + except asyncio.TimeoutError as exc: + self.log_debug('Request handler timed out.', exc_info=exc) resp = self.handle_error(request, 504) except Exception as exc: resp = self.handle_error(request, 500, exc) diff --git a/tests/test_web_protocol.py b/tests/test_web_protocol.py index ab6f2472e3f..dc1edc842bb 100644 --- a/tests/test_web_protocol.py +++ b/tests/test_web_protocol.py @@ -581,6 +581,17 @@ async def test_handle_500(srv, buf, transport, request_handler) -> None: assert b'500 Internal Server Error' in buf +async def test_handle_504(srv, buf, request_handler) -> None: + request_handler.side_effect = asyncio.TimeoutError + + srv.data_received( + b'GET / HTTP/1.0\r\n' + b'Host: example.com\r\n\r\n') + await srv._task_handler + + assert b'504 Gateway Timeout' in buf + + async def test_keep_alive(make_srv, transport, ceil) -> None: loop = asyncio.get_event_loop() srv = make_srv(keepalive_timeout=0.05) diff --git a/tests/test_web_server.py b/tests/test_web_server.py index 083a5f54128..7fe714b578e 100644 --- a/tests/test_web_server.py +++ b/tests/test_web_server.py @@ -53,7 +53,7 @@ async def handler(request): assert resp.status == 504 await resp.text() - logger.debug.assert_called_with("Request handler timed out.") + logger.debug.assert_called_with("Request handler timed out.", exc_info=exc) async def test_raw_server_do_not_swallow_exceptions(aiohttp_raw_server,