Skip to content

Commit

Permalink
Bugfix don't handle Cancellation errors in lifespan
Browse files Browse the repository at this point in the history
This fixes a regression caused by
bfb0877 whereby the cancellation
error was caught. It should instead be re-raised.
  • Loading branch information
pgjones committed Jun 3, 2024
1 parent c405dea commit 4cf3528
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/hypercorn/asyncio/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ def _call_soon(func: Callable, *args: Any) -> Any:
partial(self.loop.run_in_executor, None),
_call_soon,
)
except LifespanFailureError:
# Lifespan failures should crash the server
except (LifespanFailureError, asyncio.CancelledError):
raise
except (BaseExceptionGroup, Exception) as error:
if isinstance(error, BaseExceptionGroup):
failure_error = error.subgroup(LifespanFailureError)
if failure_error is not None:
# Lifespan failures should crash the server
raise failure_error
reraise_error = error.subgroup((LifespanFailureError, asyncio.CancelledError))
if reraise_error is not None:
raise reraise_error

self.supported = False
if not self.startup.is_set():
Expand Down
10 changes: 4 additions & 6 deletions src/hypercorn/trio/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@ async def handle_lifespan(
trio.to_thread.run_sync,
trio.from_thread.run,
)
except LifespanFailureError:
# Lifespan failures should crash the server
except (LifespanFailureError, trio.Cancelled):
raise
except (BaseExceptionGroup, Exception) as error:
if isinstance(error, BaseExceptionGroup):
failure_error = error.subgroup(LifespanFailureError)
if failure_error is not None:
# Lifespan failures should crash the server
raise failure_error
reraise_error = error.subgroup((LifespanFailureError, trio.Cancelled))
if reraise_error is not None:
raise reraise_error

self.supported = False
if not self.startup.is_set():
Expand Down

0 comments on commit 4cf3528

Please sign in to comment.