Skip to content

Commit

Permalink
Reset protocol also on error during context shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare committed Feb 3, 2024
1 parent 38d010c commit 295fa73
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pytradfri/api/aiocoap_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ async def _reset_protocol(self, exc: BaseException | None = None) -> None:

# Be responsible and clean up.
protocol = await self._get_protocol(check_reset_lock=False)
await protocol.shutdown()
self._protocol = None

# The error callbacks are called when shutting down the protocol.
# Clear the saved callbacks
self._observations_err_callbacks.clear()
try:
await protocol.shutdown()
finally:
self._protocol = None
# The error callbacks are called when shutting down the protocol.
# Clear the saved callbacks
self._observations_err_callbacks.clear()

async def shutdown(self, exc: Exception | None = None) -> None:
"""Shutdown the API events.
Expand Down

0 comments on commit 295fa73

Please sign in to comment.