Skip to content

Commit

Permalink
Merge pull request Aiven-Open#903 from Aiven-Open/nosahama/sentry-han…
Browse files Browse the repository at this point in the history
…dle-asyncio-timeout

chore, rapu: handle `asyncio.TimeoutError`
  • Loading branch information
eliax1996 authored Jul 1, 2024
2 parents 94b8855 + 60cd56f commit 6b44a63
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions karapace/rapu.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,12 @@ async def _handle_request(
)
headers = {"Content-Type": "application/json"}
resp = aiohttp.web.Response(body=body, status=status.value, headers=headers)
except (ConnectionError, aiohttp.ClientError) as connection_error:
# TCP level connection errors, e.g. TCP reset, client closes connection.
self.log.debug("Connection error.", exc_info=connection_error)
except (ConnectionError, aiohttp.ClientError, asyncio.CancelledError, asyncio.TimeoutError) as exc:
# TCP level connection errors and timeouts, e.g. TCP reset, client closes connection, task takes too long.
error_msg = "Unexpected connection or timeout error"
self.log.debug(error_msg, exc_info=exc)
# No response can be returned and written to client, aiohttp expects some response here.
resp = aiohttp.web.Response(text="Connection error", status=HTTPStatus.SERVICE_UNAVAILABLE.value)
except asyncio.CancelledError:
self.log.debug("Client closed connection")
raise
resp = aiohttp.web.Response(text=error_msg, status=HTTPStatus.SERVICE_UNAVAILABLE.value)
except Exception as ex: # pylint: disable=broad-except
self.stats.unexpected_exception(ex=ex, where="rapu_wrapped_callback")
self.log.exception("Unexpected error handling user request: %s %s", request.method, request.url)
Expand Down

0 comments on commit 6b44a63

Please sign in to comment.