Fix imap cleanup error on abort (#97097)

This commit is contained in:
Jan Bouwhuis 2023-07-23 20:30:15 +02:00 committed by GitHub
parent dc3d0fc7a7
commit fab3c5b849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -298,7 +298,8 @@ class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]):
except (AioImapException, asyncio.TimeoutError):
if log_error:
_LOGGER.debug("Error while cleaning up imap connection")
self.imap_client = None
finally:
self.imap_client = None
async def shutdown(self, *_: Any) -> None:
"""Close resources."""
@ -370,7 +371,6 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
async def _async_wait_push_loop(self) -> None:
"""Wait for data push from server."""
cleanup = False
while True:
try:
number_of_messages = await self._async_fetch_number_of_messages()
@ -412,9 +412,6 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
await idle
# From python 3.11 asyncio.TimeoutError is an alias of TimeoutError
except asyncio.CancelledError as ex:
cleanup = True
raise asyncio.CancelledError from ex
except (AioImapException, asyncio.TimeoutError):
_LOGGER.debug(
"Lost %s (will attempt to reconnect after %s s)",
@ -423,9 +420,6 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
)
await self._cleanup()
await asyncio.sleep(BACKOFF_TIME)
finally:
if cleanup:
await self._cleanup()
async def shutdown(self, *_: Any) -> None:
"""Close resources."""