Skip to content

Commit b3c98e5

Browse files
authored
Merge v1.2.1 into v1.x.x (#336)
Fix memory leak in the timer.
2 parents db33fbc + 5d6aedc commit b3c98e5

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
```
1414

1515
* `Receiver.filter()` can now properly handle `TypeGuard`s. The resulting receiver will now have the narrowed type when a `TypeGuard` is used.
16+
17+
## Bug Fixes
18+
19+
- Fixed a memory leak in the timer.

src/frequenz/channels/timer.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,20 @@ async def ready(self) -> bool: # noqa: DOC502
684684
# could be reset while we are sleeping, in which case we need to recalculate
685685
# the time to the next tick and try again.
686686
while time_to_next_tick > 0:
687-
await next(
688-
asyncio.as_completed(
689-
[
690-
asyncio.sleep(time_to_next_tick / 1_000_000),
691-
self._reset_event.wait(),
692-
]
693-
)
687+
_, pending = await asyncio.wait(
688+
[
689+
asyncio.create_task(asyncio.sleep(time_to_next_tick / 1_000_000)),
690+
asyncio.create_task(self._reset_event.wait()),
691+
],
692+
return_when=asyncio.FIRST_COMPLETED,
694693
)
694+
for task in pending:
695+
task.cancel()
696+
try:
697+
await task
698+
except asyncio.CancelledError:
699+
pass
700+
695701
self._reset_event.clear()
696702
now = self._now()
697703
time_to_next_tick = self._next_tick_time - now

0 commit comments

Comments
 (0)