Skip to content

Commit

Permalink
fix(codec): Return None after poll_data error (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioFranco committed Feb 23, 2022
1 parent d497364 commit d7cae70
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tonic/src/codec/decode.rs
Expand Up @@ -39,6 +39,7 @@ impl<T> Unpin for Streaming<T> {}
enum State {
ReadHeader,
ReadBody { compression: bool, len: usize },
Error,
}

#[derive(Debug)]
Expand Down Expand Up @@ -311,6 +312,10 @@ impl<T> Stream for Streaming<T> {

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
loop {
if let State::Error = &self.state {
return Poll::Ready(None);
}

// FIXME: implement the ability to poll trailers when we _know_ that
// the consumer of this stream will only poll for the first message.
// This means we skip the poll_trailers step.
Expand All @@ -321,6 +326,7 @@ impl<T> Stream for Streaming<T> {
let chunk = match ready!(Pin::new(&mut self.body).poll_data(cx)) {
Some(Ok(d)) => Some(d),
Some(Err(e)) => {
let _ = std::mem::replace(&mut self.state, State::Error);
let err: crate::Error = e.into();
debug!("decoder inner stream error: {:?}", err);
let status = Status::from_error(err);
Expand Down

0 comments on commit d7cae70

Please sign in to comment.