Skip to content

Commit

Permalink
🚧 Debug teardown logic
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Feb 6, 2025
1 parent 20a1353 commit 57b0ddd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions acapy_agent/core/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ async def __aenter__(self):
)
# Cancel the teardown task if the session becomes active again
if self._teardown_task:
LOGGER.debug(
"Cancelling existing teardown task for profile: %s.", self._profile
)
self._teardown_task.cancel()
self._teardown_task = None
return self
Expand All @@ -244,7 +247,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
self._entered,
self._profile,
)
if not self._awaited and not self._entered:
if not self._awaited and not self._entered and self._teardown_task is None:
LOGGER.debug(
"Starting countdown for profile session teardown for profile: %s.",
self._profile,
Expand All @@ -255,6 +258,10 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
async def _countdown_teardown(self):
"""Wait for a countdown period before tearing down the session."""
try:
LOGGER.debug(
"Starting countdown for profile session teardown for profile: %s.",
self._profile,
)
await asyncio.sleep(5) # Wait for 5 seconds
if not self._active:
LOGGER.debug(
Expand All @@ -263,13 +270,20 @@ async def _countdown_teardown(self):
)
await self._teardown()
self._active = False
self._teardown_task = None
LOGGER.debug("Profile session inactive for profile: %s.", self._profile)
else:
LOGGER.debug(
"Profile session became active again, skipping teardown for profile: %s.",
self._profile,
)
except asyncio.CancelledError:
LOGGER.debug(
"Countdown for profile session teardown cancelled for profile: %s.",
self._profile,
)
finally:
self._teardown_task = None
LOGGER.debug("Teardown task completed for profile: %s.", self._profile)

@property
def active(self) -> bool:
Expand Down

0 comments on commit 57b0ddd

Please sign in to comment.