From 5ab12796cf229c323492d667e12e6eda91a1f3fe Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 25 Sep 2024 11:39:20 +0200 Subject: [PATCH 1/3] Clear release notes Signed-off-by: Leandro Lucarella --- RELEASE_NOTES.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4d761c95..96a0240b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,19 +1,17 @@ # Frequenz channels Release Notes +## Summary + + + ## Upgrading -- `FileWatcher`: The file polling mechanism is now forced by default. This provides reliable and consistent file monitoring on network file systems (e.g., CIFS). However, it may have a performance impact on local file systems or when monitoring a large number of files. - - To disable file polling, set the `force_polling` parameter to `False`. - - The `polling_interval` parameter defines the interval for polling changes. This is relevant only when polling is enabled and defaults to 1 second. + ## New Features -- `Timer.reset()` now supports setting the interval and will restart the timer with the new interval. + ## Bug Fixes -- `FileWatcher`: - - Fixed `ready()` method to return False when an error occurs. Before this fix, `select()` (and other code using `ready()`) never detected the `FileWatcher` was stopped and the `select()` loop was continuously waking up to inform the receiver was ready. - - Reports file events correctly on network file systems like CIFS. - -- `Timer.stop()` and `Timer.reset()` now immediately stop the timer if it is running. Before this fix, the timer would continue to run until the next interval. + From 6a6907ff0024ae4876d5c6e87d1f8a7d67cdaff5 Mon Sep 17 00:00:00 2001 From: Sahas Subramanian Date: Fri, 15 Nov 2024 18:00:45 +0100 Subject: [PATCH 2/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 3/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.