Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codec): Return None after poll_data error #921

Merged
merged 1 commit into from Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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