Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Stop running streams on disconnect - #356

Open
Marenz wants to merge 1 commit into
frequenz-floss:v1.x.xfrom
Marenz:fix/stop-streams-on-disconnect
Open

Marenz wants to merge 1 commit into
frequenz-floss:v1.x.xfrom
Marenz:fix/stop-streams-on-disconnect

Conversation

@Marenz

@Marenz Marenz commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

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_streams in tests/test_client_timeouts.py) that starts a stream, disconnects, and asserts the stream task actually stopped.

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
Marenz requested review from a team as code owners November 30, 2026 09:36
@Marenz
Marenz requested review from ela-kotulska-frequenz and llucax and removed request for a team November 30, 2026 09:36
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests part:dispatcher labels 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:dispatcher part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants