Repository navigation
Conversation
DispatchApiClient.stream() starts a background task per microgrid to retry the gRPC stream forever. disconnect() (and leaving the client as an async context manager) only closed the channel, so those tasks kept running and kept failing once the channel was gone. Override __aexit__ to stop every stream before closing the channel, since both disconnect() and the context manager exit through it. Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Marenz
requested review from
ela-kotulska-frequenz and
llucax
and removed request for
a team
November 30, 2026 09:36
llucax
approved these changes
Nov 30, 2026
Comment on lines
+139
to
+142
| `BaseApiClient.disconnect()` and the async context manager (`async with`) | ||
| both exit through this method, so streams started with `stream()` are | ||
| always stopped, whether the client is disconnected explicitly or by | ||
| leaving a `with` block. |
Contributor
There was a problem hiding this comment.
I was really confused by this __aexit__ and the mention to an non-existent disconnect().
Damn this is ugly!!! I think we should change BaseApiClient to do the reverse, make __aexit__ call disconnect() instead of the other way around 😒
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DispatchApiClient.stream()starts a background task per microgrid that keeps retrying the gRPC stream forever.disconnect()(and leaving the client as an async context manager) only closed the channel, so those background tasks kept running and kept failing once the channel was gone.This stops every running stream before closing the channel, so
disconnect()and the async context manager both leave no background tasks behind.Added a regression test (
test_disconnect_stops_streamsintests/test_client_timeouts.py) that starts a stream, disconnects, and asserts the stream task actually stopped.