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
#[tokio::test(flavor = "multi_thread")]asyncfntokio_file_write(){let root_dir = "/tmp/chaos/td/test";letmut f = tokio::fs::File::create(root_dir).await.unwrap();// XKBlet data = [96u8;1024*512];let l = f.write(&data.to_vec()).await.unwrap();assert_eq!(1024 * 512, l);}
#[tokio::test(flavor = "multi_thread")]asyncfntokio_file_write(){let root_dir = "/tmp/chaos/td/test";letmut f = tokio::fs::File::create(root_dir).await.unwrap();// XKBlet data = [96u8;1024*512];
f.write_all(&data.to_vec()).await.unwrap();}
I expected to see this happen:
I also tested with the std::fs::File, and it works as expected.
#[test]fnstd_file_write(){let root_dir = "/tmp/chaos/td/test";letmut f = std::fs::File::create(root_dir).unwrap();// XKBlet data = [96u8;1024*512];
f.write_all(&data.to_vec()).unwrap();}
Output:
called `Result::unwrap()` on an `Err` value: Os { code: 28, kind: StorageFull, message: "No space left on device" }stack backtrace: 0: rust_begin_unwind at /rustc/f3623871cfa0763c95ebd6ceafaa6dc2e44ca68f/library/std/src/panicking.rs:617:5
Instead, this happened:
The tokio::fs::File's writes only contain partial bytes and didn't raise any errors!
running 1 testtest tests::standalone_read_write::tokio_file_write ... ok
➜ td ls -lh
total 448K
drwx------ 2 root root 16K Sep 13 08:28 lost+found
-rw-rw-r-- 1 weny weny 428K Sep 13 09:10 test
The text was updated successfully, but these errors were encountered:
Cool,flush throws a NoSpace error. But why after calling the sync_all didn't throw any errors?
Are there any differences between the sync_all and flush?
Yes, sync_all and flush are completely different. The flush method ensures that things not yet written by Rust are written to the OS. The sync_all method ensures that everything written to the OS is flushed to disk.
Arguably the sync_all method should do a flush first.
Version
v1.29.1
Platform
The output of
uname -a
(UNIX), or version and 32 or 64-bit (Windows)Linux 6.2.0-25-generic #25-Ubuntu SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
Description
Enter your issue details here.
One way to structure the description:
tokio::fs::File
only writes partial bytes and doesn't raise any errors.We designed some chaos tests, which simulate what problems will occur when the disk is full.
I tried this code:
I expected to see this happen:
I also tested with the
std::fs::File
, and it works as expected.Output:
Instead, this happened:
The
tokio::fs::File
's writes only contain partial bytes and didn't raise any errors!The text was updated successfully, but these errors were encountered: