Skip to content

Commit 85f3181

Browse files
authored
Disconnect dispatcher at cleanup
1 parent 30e84b8 commit 85f3181

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
## Bug Fixes
1616

17-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
17+
- Fixed an issue in the `Dispatcher` class where the client connection was not properly disconnected during cleanup, potentially causing unclosed socket errors.

src/frequenz/dispatch/_dispatcher.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import logging
1010
from asyncio import Event
1111
from datetime import timedelta
12+
from types import TracebackType
1213
from typing import Awaitable, Callable, Self
1314

1415
from frequenz.channels import Receiver
@@ -361,6 +362,25 @@ async def __aenter__(self) -> Self:
361362
await self.wait_for_initialization()
362363
return self
363364

365+
@override
366+
async def __aexit__(
367+
self,
368+
exc_type: type[BaseException] | None,
369+
exc_value: BaseException | None,
370+
traceback: TracebackType | None,
371+
) -> None:
372+
"""Exit an async context.
373+
374+
Stop this background service and disconnect the client.
375+
376+
Args:
377+
exc_type: The exception type.
378+
exc_value: The exception value.
379+
traceback: The traceback object.
380+
"""
381+
await super().__aexit__(exc_type, exc_value, traceback)
382+
await self._client.disconnect()
383+
364384
def new_lifecycle_events_receiver(
365385
self, dispatch_type: str
366386
) -> Receiver[DispatchEvent]:

0 commit comments

Comments
 (0)