Skip to content

Commit 0fe4b88

Browse files
edef1ctaiki-e
authored andcommitted
FillBuf: don't poll a second time on EOF
There is no hard guarantee that polling a second time will return Poll::Ready, and this is particularly likely to break in the EOF case, which is precisely where we don't need to do so at all. Both tokio::io::BufReader and futures::io::BufReader always attempt to read from the underlying reader when the buffer is empty, rather than fusing EOF.
1 parent f75c4c1 commit 0fe4b88

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

futures-util/src/io/fill_buf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ where
3030
let reader = this.reader.take().expect("Polled FillBuf after completion");
3131

3232
match Pin::new(&mut *reader).poll_fill_buf(cx) {
33+
// We don't need to poll a second time for EOF, and doing so is likely to return Poll::Pending
34+
Poll::Ready(Ok(&[])) => Poll::Ready(Ok(&[])),
3335
// With polonius it is possible to remove this inner match and just have the correct
3436
// lifetime of the reference inferred based on which branch is taken
3537
Poll::Ready(Ok(_)) => match Pin::new(reader).poll_fill_buf(cx) {

0 commit comments

Comments
 (0)