Skip to content

Commit

Permalink
Print stacktrace when catching TimeoutError (#3414)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitrut authored and asvetlov committed Dec 1, 2018
1 parent eb951c8 commit 66d1f9c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES/3414.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix `asyncio.TimeoutError` stack trace not logged, when it is caught
in the handler.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Paulius Šileikis
Paulus Schoutsen
Pavel Kamaev
Pavel Polyakov
Pawel Kowalski
Pawel Miech
Pepe Osca
Philipp A.
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 66d1f9c

Please sign in to comment.