mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-18 05:53:59 +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._http: HttpSession = HttpSession()
|
||||||
self._reports: LocationReportsFetcher = LocationReportsFetcher(self)
|
self._reports: LocationReportsFetcher = LocationReportsFetcher(self)
|
||||||
|
self._closed: bool = False
|
||||||
|
|
||||||
def _set_login_state(
|
def _set_login_state(
|
||||||
self,
|
self,
|
||||||
@@ -473,8 +474,21 @@ class AsyncAppleAccount(BaseAppleAccount):
|
|||||||
|
|
||||||
Should be called when the object will no longer be used.
|
Should be called when the object will no longer be used.
|
||||||
"""
|
"""
|
||||||
await self._anisette.close()
|
if self._closed:
|
||||||
await self._http.close()
|
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)
|
@require_login_state(LoginState.LOGGED_OUT)
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user