Description
Original issue is chatmail/core#2032
I have prepared a minimal example demonstrating the bug, which depends only on async-std
1.6.5.
An example which you can unpack and run with cargo run
: filedrop.tar.gz
The source code for reference:
use async_std::prelude::*;
async fn create_file() {
let mut file = async_std::fs::OpenOptions::new()
.create(true)
.write(true)
.open("foo.txt")
.await
.unwrap();
file.write_all(b"foobarbaz").await.unwrap();
//file.flush().await.unwrap();
eprintln!("before drop");
}
async fn test() {
let tsk = async_std::task::spawn(async move {
create_file().await;
eprintln!("after drop");
});
tsk.await;
}
fn main() {
async_std::task::block_on(test());
}
I built this example in the following configuration:
- Debian sid as a host machine.
- NetBSD 9.1 as a guest, installed in qemu (kvm)
- Rust 1.47.0 installed on NetBSD via rustup.
When I execute cargo run
, the program prints before drop
and gets stuck. Apparently the problem is that despite what comment says, executor does not handle blocking operation in Drop correctly:
Line 314 in 11196c8
After waiting a minute and terminating the program, the file foo.txt
is created, but is empty.
When I uncomment the line file.flush().await.unwrap();
, the program prints
before drop
after drop
and exits.
On my Linux machine this works correctly. It is not a QEMU bug, as the same problem is experienced on some Android phones, see original issue chatmail/core#2032