mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-17 21:53:57 +02:00
Fix unclosed aiohttp client session warnings
- Add proper session state management to HttpSession, RemoteAnisetteProvider, and AsyncAppleAccount - Implement idempotent close() methods with _closed flags - Improve cleanup order and error handling - Prevent new session creation after close() is called Fixes resource leaks and eliminates aiohttp unclosed session warnings.
This commit is contained in:
@@ -375,6 +375,7 @@ class AsyncAppleAccount(BaseAppleAccount):
|
||||
|
||||
self._http: HttpSession = HttpSession()
|
||||
self._reports: LocationReportsFetcher = LocationReportsFetcher(self)
|
||||
self._closed: bool = False
|
||||
|
||||
def _set_login_state(
|
||||
self,
|
||||
@@ -473,8 +474,21 @@ class AsyncAppleAccount(BaseAppleAccount):
|
||||
|
||||
Should be called when the object will no longer be used.
|
||||
"""
|
||||
await self._anisette.close()
|
||||
await self._http.close()
|
||||
if self._closed:
|
||||
return # Already closed, make it idempotent
|
||||
|
||||
self._closed = True
|
||||
|
||||
# Close in proper order: anisette first, then HTTP session
|
||||
try:
|
||||
await self._anisette.close()
|
||||
except Exception as e:
|
||||
logger.warning("Error closing anisette provider: %s", e)
|
||||
|
||||
try:
|
||||
await self._http.close()
|
||||
except Exception as e:
|
||||
logger.warning("Error closing HTTP session: %s", e)
|
||||
|
||||
@require_login_state(LoginState.LOGGED_OUT)
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user