-
Notifications
You must be signed in to change notification settings - Fork 389
Make sure to sync on file-io.rs tokio test #4370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tokio `AsyncWriteExt::write` doesn't actually ensure that the contents have written, it just *starts* the write operation. To ensure that the file has actually been written, we need to `sync_all` first.
To add more context, me and nora tried async fn test_create_and_write() -> io::Result<()> {
let path = utils::prepare("foo.txt");
let mut file = File::create(&path).await?;
// Write 10 bytes to the file.
let a = file.write(b"some bytes").await?;
assert_eq!(a, 10);
assert_eq!(file.metadata().await.unwrap().len(), 10);
remove_file(&path).unwrap();
Ok(())
} and the test only fails on second assert in certain seeds. That means the file metadata is not completely synced before we access it. |
Isn't that a tokio bug? When a single task creates a file and then tries to read it, surely that should just work? |
The way the tokio code is written makes me think that this is deliberate behavior. I haven't found any docs about this though, so I will report that to tokio to at least ask them to document this behavior. |
Not having program order establish happens-before is at least rather unconventional... Cc @Darksonn |
filed tokio-rs/tokio#7378 |
Is this PR required to un-break CI or should the other one be enough? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to improve docs, but this is intended behavior. Tokio's file behaves like BufWriter<File>
in std.
this one is required. i was able to produce failures with write_all locally (though it might be possible that just write_all reduces the amount of failures) |
Miri subtree update r? `@ghost` Includes rust-lang/miri#4370 to unbreak PR CI. (So we're committing to having bda28aa38 in the Miri history by landing this, whether or not that Miri PR lands.) Cc `@Noratrieb` `@tiif`
Tokio
AsyncWriteExt::write
doesn't actually ensure that the contents have written, it just starts the write operation. To ensure that the file has actually been written, we need tosync_all
first.actually fixes #4367