Found bug! It is **NOT** safe to pin and poll a stack future in a `poll*` Future method.

Fortune for rsh's current commit: Blessing − 吉
sock-buffering
Avril 3 years ago
parent 7cad244c16
commit 5d5748b5ea
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -199,6 +199,35 @@ impl<T: AsyncRead + Unpin + ?Sized, const SIZE: usize> Buffered<T, SIZE>
self.buffer.drain(..copy);
copy
}
pub async fn read_test(&mut self, buf: &mut [u8]) -> io::Result<usize>
{
use tokio::prelude::*;
let mut w = 0;
/*if self.buffer.is_empty()
{
self.fill_buffer().await?;
}*/
while w < buf.len() {
match self.try_take_buffer(&mut &mut buf[w..]) {
0 => {
if !self.fill_buffer().await?
&& self.buffer.is_empty()
{
println!("Buffer empty");
break;
} else {
println!("Buffer filled");
}
},
x => w+=x,
}
}
println!("Done: {}", w);
Result::<usize, io::Error>::Ok(w)
}
}
// XXX: I don't think writing futures like this is safe. Expand the inline `async{}`s into actual polling.
@ -215,8 +244,8 @@ where T: AsyncRead
/*if this.buffer.is_empty()
{
this.fill_buffer().await?;
}*/
this.fill_buffer().await?;
}*/
while w < buf.len() {
match this.try_take_buffer(&mut &mut buf[w..]) {
@ -297,8 +326,11 @@ mod tests
Result::<_, std::io::Error>::Ok(())
});
let mut output =Vec::new();
tokio::io::copy(&mut rx, &mut output).await?;
let mut output = vec![0u8; DATA.len()*2];
// Bug found! Pinning and polling that stack future in `poll_read` does NOT work!
// The exact same works as a real async function.
assert_eq!(rx.read_test(&mut output[..DATA.len()]).await?, DATA.len());
assert_eq!(rx.read_test(&mut output[DATA.len()..]).await?, DATA.len());
back.await.expect("Back panick")?;

Loading…
Cancel
Save