Standard library file writing can lead to silent data loss
I recently came accross this issue on the Rust issue tracker: https://github.com/rust-lang/rust/issues/98338
Apparently, file writing code like this:
let mut file = File::create("foo.txt")?;
file.write_all(b"Hello, world!")?;
Ok(())
or even fs::write("foo.txt", b"Hello, world!")
will just silently discard any error returned when closing the file.
On some filesystems (notably NFS), the close operation may be used to flush internal buffers and can return write errors. Rust will just silently discard these errors, leading to silent data loss.
This discovery has made me feel quite sketched out. How is this not a bigger deal? How come practically nobody is talking about this? Especially for a language like Rust, which is usually very conscientious about checking every error and handling every edge case, this feels like a big oversight.