-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Race condition in std::fs::create_dir_all
.
#33707
Comments
The libs team discussed this during triage yesterday and the conclusion was that this does indeed seem ok to implement. Given the new information about other implementations along with a shift in intention for the "nice APIs" we provide like this and @dpc do you wanna send a PR? |
Ah it was also brought up that we probably want to alter the documentation as well to indicate what version of Rust includes the new behavior. |
I don't really have a Rust development setup nor the experience with it, so I'll not be able to provide a PR. But isn't #30152 still applicable? |
Yeah it should still work, we'd probably just want to add some more tests as well |
This is an annoying problem with the Rust standard library. rust-lang/rust#33707
Can't this be closed now that #39799 is merged? |
I just got bitten by this, took me a long time to find it and I see the issue was raised before in #30152
It's very non-obvious that
std::fs::create_dir_all
- which whole purpose of is to make sure the dir exists, can fail due to the fact that the dir was created concurrently.The PR to fix it #30152 was rejected due to "Concurrent operations can't always be detected and when they do happen on the filesystem it often indicates that something else is going awry and needs to be kicked up further."
But please note that
std::fs::create_dir_all
is a convenience function, and not one directly mapping to a posix fs operation. Ifstdlib
provides a convenience function, I think it should provide the sanest, and most robust one - not one with a big gotcha inside. The fact that there's a race condition between multiple calls tostd::fs::create_dir_all
is entirely a implementation choice and just a wrong behavior.IMO any sane implementation should consider not takign care of this race condition a bug:
I've checked some other standard libraries and all are doing the right thing:
Note that return value of
create_directories(ph.parent_path());
is ignored, not returned upwards, like in Rust implementation. And exception is thrown only ifph
exists but is not a directory.Think how many other Rust projects might have undetected race condition as they assumed the
create_dir_all
will do the right thing. Short googling already pointed other project that got bitten: https://github.com/droundy/bigbro/blob/464bfae81de4ad695a158315e3c75d6d21e382a2/src/lib.rs#L43The text was updated successfully, but these errors were encountered: