tokio-util: stop polling StreamReader after EOF (#8332)

This commit is contained in:
MAAZIZ Adel Ayoub
2026-08-07 21:59:51 +08:00
committed by GitHub
parent cc8c053421
commit a5b2d1ff69
2 changed files with 29 additions and 1 deletions
+19
View File
@@ -33,3 +33,22 @@ async fn test_stream_reader() -> std::io::Result<()> {
Ok(())
}
#[tokio::test]
async fn test_stream_reader_does_not_poll_after_eof() -> std::io::Result<()> {
// the first poll of this stream will return `Poll::Ready(None)`,
// and the second poll will panic
let stream = futures::stream::unfold((), |_| async { None::<(std::io::Result<Bytes>, ())> });
let read = StreamReader::new(stream);
tokio::pin!(read);
let mut buf = [0; 1];
// the first poll hits the inner stream,
// and the inner stream returns `Poll::Ready(None)`.
assert_eq!(read.read(&mut buf).await?, 0);
// the second poll doesn't hit the inner stream,
// so this `.read()` doesn't panic.
assert_eq!(read.read(&mut buf).await?, 0);
Ok(())
}