Skip to content

Commit

Permalink
Handle cancellation due client disconnect
Browse files Browse the repository at this point in the history
Handle client disconnect during the request handling gracefully.
E.g. if no primary selected, asyncio.sleep gets cancelled, and aiohttp
handles it correctly, and it should not trigger internal server errors.
  • Loading branch information
tvainika committed Mar 9, 2023
1 parent ed90944 commit 90a360a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions karapace/rapu.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ async def _handle_request(
data = ex.body
status = ex.status
headers = ex.headers
except asyncio.CancelledError:
# Re-raise if aiohttp cancelled the task (e.g. client disconnected) without internal server error
raise
except: # pylint: disable=bare-except
self.log.exception("Internal server error")
headers = {"Content-Type": "application/json"}
Expand Down

0 comments on commit 90a360a

Please sign in to comment.