Skip to content

Commit

Permalink
fix: ensure cancellation is not swallowed on connect failure and in r…
Browse files Browse the repository at this point in the history
…esponse handlers (#57)
  • Loading branch information
bdraco authored Jan 24, 2025
1 parent f1e9192 commit d805a4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/aioharmony/hubconnector_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import asyncio
import logging
import socket
import sys
from contextlib import suppress
from typing import Optional, Union
from urllib.parse import urlparse
Expand Down Expand Up @@ -399,6 +400,12 @@ async def _listener(self, websocket=None) -> None:

except asyncio.CancelledError:
_LOGGER.debug("%s: Received STOP for listener", self._ip_address)
if (
sys.version_info >= (3, 11)
and (task := asyncio.current_task())
and task.cancelling()
):
raise
break

# pylint: disable=broad-except
Expand Down
7 changes: 7 additions & 0 deletions src/aioharmony/hubconnector_xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import asyncio
import json
import logging
import sys
from typing import Optional
from uuid import uuid4

Expand Down Expand Up @@ -215,6 +216,12 @@ def remove_handlers():
)
# Remove the handlers.
remove_handlers()
if (
sys.version_info >= (3, 11)
and (task := asyncio.current_task())
and task.cancelling()
):
raise
return False
except OSError as exc:
_LOGGER.log(
Expand Down
7 changes: 7 additions & 0 deletions src/aioharmony/responsehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import asyncio
import logging
import sys
from datetime import datetime, timedelta, timezone
from re import Pattern
from typing import NamedTuple, Optional, Union
Expand Down Expand Up @@ -312,6 +313,12 @@ async def _callback_handler(self) -> None:

except asyncio.CancelledError:
_LOGGER.debug("%s: Received STOP for callback handler", self._name)
if (
sys.version_info >= (3, 11)
and (task := asyncio.current_task())
and task.cancelling()
):
raise
break

# Need to catch everything here to prevent an issue in a
Expand Down

0 comments on commit d805a4a

Please sign in to comment.