From 6a6907ff0024ae4876d5c6e87d1f8a7d67cdaff5 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Fri, 15 Nov 2024 18:00:45 +0100 Subject: [PATCH 1/3] Fix memory leak in the timer We were creating two futures, but only awaiting until the one of them finished and not canceling the second. Because `reset()` was never called, we were just creating more and more futures that would never complete. This change fixes this by canceling the second task immediately after the first one is complete. Signed-off-by: Sahas Subramanian --- src/frequenz/channels/timer.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/frequenz/channels/timer.py b/src/frequenz/channels/timer.py index b2f0338a..a697b234 100644 --- a/src/frequenz/channels/timer.py +++ b/src/frequenz/channels/timer.py @@ -682,14 +682,20 @@ async def ready(self) -> bool: # noqa: DOC502 # could be reset while we are sleeping, in which case we need to recalculate # the time to the next tick and try again. while time_to_next_tick > 0: - await next( - asyncio.as_completed( - [ - asyncio.sleep(time_to_next_tick / 1_000_000), - self._reset_event.wait(), - ] - ) + _, pending = await asyncio.wait( + [ + asyncio.create_task(asyncio.sleep(time_to_next_tick / 1_000_000)), + asyncio.create_task(self._reset_event.wait()), + ], + return_when=asyncio.FIRST_COMPLETED, ) + for task in pending: + task.cancel() + try: + await task + except asyncio.CancelledError: + pass + self._reset_event.clear() now = self._now() time_to_next_tick = self._next_tick_time - now From b0eabec258d048ae0c31546d839325ed95079196 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Fri, 15 Nov 2024 18:37:04 +0100 Subject: [PATCH 2/3] Update release notes Signed-off-by: Sahas Subramanian --- RELEASE_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 96a0240b..50e99499 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -14,4 +14,4 @@ ## Bug Fixes - +- Fixed a memory leak in the timer. From b73069fd944ecb9cbf37fdf181826d88d8fa58c3 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Mon, 18 Nov 2024 10:23:02 +0100 Subject: [PATCH 3/3] Prepare for v1.2.1 Signed-off-by: Sahas Subramanian --- RELEASE_NOTES.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 50e99499..2ab341b5 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,17 +1,5 @@ # Frequenz channels Release Notes -## Summary - - - -## Upgrading - - - -## New Features - - - ## Bug Fixes - Fixed a memory leak in the timer.