Skip to content

Commit

Permalink
don't clear host_task from CancelScope if __exit__ is called incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 13, 2024
1 parent 4a65331 commit f45b7d1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,16 @@ def __exit__(
exc_tb: TracebackType | None,
) -> bool | None:
del exc_tb
try:
if not self._active:
raise RuntimeError("This cancel scope is not active")
if current_task() is not self._host_task:
raise RuntimeError(
"Attempted to exit cancel scope in a different task than it was "
"entered in"
)

if not self._active:
raise RuntimeError("This cancel scope is not active")
if current_task() is not self._host_task:
raise RuntimeError(
"Attempted to exit cancel scope in a different task than it was "
"entered in"
)

try:
assert self._host_task is not None
host_task_state = _task_states.get(self._host_task)
if host_task_state is None or host_task_state.cancel_scope is not self:
Expand Down

0 comments on commit f45b7d1

Please sign in to comment.