You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got an issue with data written to a file right before exiting is lost.
It seems it's a race condition somewhere because, with a lot of tries the data can show up, and adding a small delay solves it consistently.
I'm creating the issue in this repo because I'm not sure which part of the stack is the issue.
Here's a minimal repro (see below for a full crate):
use smol::io::AsyncWriteExt;fnmain(){
smol::block_on(write_file());}asyncfnwrite_file(){let data = b"Now you see me";letmut file = smol::fs::File::create("now-you-dont.txt").await.unwrap();
file.write_all(data).await.unwrap();}
Something that seems interesting is that if I use write instead of write_all and output the number of written bytes, it's 14 as expected. Outputting that number using a print adds enough delay for the data to be written, but using the process exit code I get the right number and an empty file.
Here's a repo with a full crate so that all dependencies are pinned: smol-bug-repro.
I tested this using all combinations of:
rustc
1.76.0 (07dca489a 2024-02-04) (built from a source tarball)
1.77.1 (7cf61ebde 2024-03-27) (built from a source tarball)
smol
1.3.0
2.0.0
Hopefully you can reproduce, otherwise let me know what I can do to help.
The text was updated successfully, but these errors were encountered:
Hi,
I've got an issue with data written to a file right before exiting is lost.
It seems it's a race condition somewhere because, with a lot of tries the data can show up, and adding a small delay solves it consistently.
I'm creating the issue in this repo because I'm not sure which part of the stack is the issue.
Here's a minimal repro (see below for a full crate):
Something that seems interesting is that if I use
write
instead ofwrite_all
and output the number of written bytes, it's 14 as expected. Outputting that number using a print adds enough delay for the data to be written, but using the process exit code I get the right number and an empty file.Here's a repo with a full crate so that all dependencies are pinned: smol-bug-repro.
I tested this using all combinations of:
1.76.0 (07dca489a 2024-02-04) (built from a source tarball)
1.77.1 (7cf61ebde 2024-03-27) (built from a source tarball)
1.3.0
2.0.0
Hopefully you can reproduce, otherwise let me know what I can do to help.
The text was updated successfully, but these errors were encountered: