-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Tokio file visibility problem #4796
Comments
As I further narrowed down, it turns out that nothing to do with notify or synchronizations, the problem may lie in |
You need to call |
Right. This appears to be a misunderstanding of how I see how the documentation of |
Thanks for your explanation, I will rewrite the MRE to see if the problem resolves :) |
I've found the root cause.
Switch to |
Maybe the documentation could be more clear to remind users of such internal buffering mechanisms :) |
Version
$ cargo tree | grep tokio └── tokio v1.19.2 └── tokio-macros v1.8.0 (proc-macro)
Platform
$ uname -a Linux VM-16-12-ubuntu 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Description
What does my program do
In
src/main.rs
, 3 async tasks cooperate with each other, synchronized bytokio::sync::Notify
.write_offset
and notify flush task.write_offset
, flush file and updateflush_offset
towrite_offset
.flush_offset
as the persisted file length, read the fileregion
[0, flush_offset)
and checks if data read matches data written.What is expected
As these async tasks are carefully synchronized, when reader initiates a read to file,
it should be able to see the data written by writer is already persisted, the file's length
in file metadata is equal to
flush_offset
, and the file content is the same as data written.What actually happens
When run this program in a loop, given enough time to repeat, it can always panic at the assert statement in reader
task,
complaining that file's length in metadata is 0, and file content read is empty.
From above logs, it's clear that
sync_all
succeeded before read (as we can see "flush: 123" was printed),even though when reader read file it could only see an empty file.
The problem can always be reproduced in platform:
$ uname -a Linux VM-16-12-ubuntu 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux $ rustup show Default host: x86_64-unknown-linux-gnu installed toolchains -------------------- stable-x86_64-unknown-linux-gnu nightly-x86_64-unknown-linux-gnu (default) active toolchain ---------------- nightly-x86_64-unknown-linux-gnu (default) rustc 1.64.0-nightly (830880640 2022-06-28)
But interestingly, this problem could not yet be reproduced in ARM platforms, including Raspberry Pi and Macbook Pro M1.
The minimal reproducible example can be found in this repo.
The text was updated successfully, but these errors were encountered: