Skip to content

Commit

Permalink
Exhaust AsyncBufRead reader
Browse files Browse the repository at this point in the history
When the decoder goes into State::Done, the decoder is considered done
with reading. Therefore no calls will be made to the underlying
reader. As a consequence, the reader never reaches EOF state. i.e. The
AsyncBufRead never returns `Poll::Ready(Ok(&[]))`.
This is problematic as this prevents underlaying streams, readers and
channels to gracefully shutdown.

To solve this issue, the decoder will make one interation more into
state::Decoding. This forces one last read into the underlying reader
by calling poll_fill_buffer. before it goes into State::Done via
State::Flushing.
  • Loading branch information
svenrademakers committed Dec 2, 2023
1 parent 4c6ae38 commit aefa146
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/futures/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
let done = this.decoder.decode(&mut input, output)?;
let len = input.written().len();
this.reader.as_mut().consume(len);
if done {
State::Flushing
} else {
State::Decoding
}
State::Decoding
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/tokio/bufread/generic/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,7 @@ impl<R: AsyncBufRead, D: Decode> Decoder<R, D> {
let done = this.decoder.decode(&mut input, output)?;
let len = input.written().len();
this.reader.as_mut().consume(len);
if done {
State::Flushing
} else {
State::Decoding
}
State::Decoding
}
}

Expand Down

0 comments on commit aefa146

Please sign in to comment.