Skip to content

Commit

Permalink
cnidarium(watch): always check that the channel is open (#4474)
Browse files Browse the repository at this point in the history
## Describe your changes

We need to bind server resource usage to the lifetime of a connection.
Currently, the way client connection termination is percolated to the
state watcher task is that sending over the channel would fail as soon
as the receive handler is dropped. However, this is insufficient because
we only send over the channel in specific cases. Instead, we should be
checking unconditionally.

## Checklist before requesting a review

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > Mechanical change
  • Loading branch information
erwanor authored May 28, 2024
1 parent 94a4ac1 commit 2a15950
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/cnidarium/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async fn watch_changes(
tx: tokio::sync::mpsc::Sender<Result<WatchResponse, tonic::Status>>,
) -> anyhow::Result<()> {
let mut changes_rx = storage.subscribe_changes();
loop {
while !tx.is_closed() {
// Wait for a new set of changes, reporting an error if we don't get one.
if let Err(e) = changes_rx.changed().await {
tx.send(Err(tonic::Status::internal(e.to_string()))).await?;
Expand Down Expand Up @@ -252,4 +252,5 @@ async fn watch_changes(
}
}
}
return Ok(());
}

0 comments on commit 2a15950

Please sign in to comment.