io: do not treat zero-length reads as EOF in Chain (#8251)

This commit is contained in:
MAAZIZ Adel Ayoub
2026-07-03 08:31:33 +02:00
committed by GitHub
parent 9fe3c5619d
commit dd683aba3f
2 changed files with 15 additions and 1 deletions
+3 -1
View File
@@ -94,7 +94,9 @@ where
if !*me.done_first {
let rem = buf.remaining();
ready!(me.first.poll_read(cx, buf))?;
if buf.remaining() == rem {
// A read that fills nothing only indicates EOF if the buffer
// had capacity to begin with.
if buf.remaining() == rem && rem != 0 {
*me.done_first = true;
} else {
return Poll::Ready(Ok(()));
+12
View File
@@ -14,3 +14,15 @@ async fn chain() {
assert_ok!(rd.read_to_end(&mut buf).await);
assert_eq!(buf, b"hello world");
}
#[tokio::test]
async fn empty_read_does_not_skip_first() {
let mut buf = Vec::new();
let rd1: &[u8] = b"hello ";
let rd2: &[u8] = b"world";
let mut rd = rd1.chain(rd2);
assert_eq!(assert_ok!(rd.read(&mut []).await), 0);
assert_ok!(rd.read_to_end(&mut buf).await);
assert_eq!(buf, b"hello world");
}