Skip to content

Commit

Permalink
fix(tonic): allows the server to prematurely close the stream in clie…
Browse files Browse the repository at this point in the history
…nt side streaming

Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Jun 13, 2024
1 parent d4f0984 commit a727d1c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions madsim-tonic/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;

use futures_util::{pin_mut, Stream, StreamExt};
use tonic::codegen::http::uri::PathAndQuery;
use tracing::instrument;
use tracing::{debug, instrument};

use crate::{
codegen::{BoxMessage, IdentityInterceptor, RequestExt},
Expand Down Expand Up @@ -183,7 +183,11 @@ impl<F: Interceptor> Grpc<crate::transport::Channel, F> {
// send requests
pin_mut!(stream);
while let Some(item) = stream.next().await {
tx.send(Box::new(item)).await?;
/// allows the server to prematurely close the stream
if tx.send(Box::new(item)).await.is_err() {
debug!("send stream unexpectedly closed");
break;
}
}
Ok(())
}
Expand Down

0 comments on commit a727d1c

Please sign in to comment.