Skip to content

Commit

Permalink
Merge pull request #534 from lona-web-org/fscherf/fix-aiohttp-handler…
Browse files Browse the repository at this point in the history
…-cancellation-issue

fix aiohttp handler cancellation issue
  • Loading branch information
fscherf authored Feb 3, 2024
2 parents c9a6be3 + 44cc695 commit 408caaa
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lona/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __init__(self, project_root: str,
'*', static_url, self._handle_static_file_request)

self._app.router.add_route(
'*', '/{path_info:.*}', self._handle_http_request)
'*', '/{path_info:.*}', self._shielded_handle_http_request)

# setup view loader
server_logger.debug('setup view loader')
Expand Down Expand Up @@ -636,6 +636,18 @@ async def _handle_http_request(self, http_request):

return self._render_response(response)

async def _shielded_handle_http_request(self, request):
"""
Runs `Server._handle_http_request` shielded from cancelation
aiohttp 3.9 introduced web handler cancellation
(https://docs.aiohttp.org/en/v3.9.0/web_advanced.html#web-handler-cancellation)
which creates race conditions in the connections teardown code when
enabled.
"""

return await asyncio.shield(self._handle_http_request(request))

# public api ##############################################################
@overload
def run_coroutine_sync(
Expand Down

0 comments on commit 408caaa

Please sign in to comment.