Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRace condition in `std::fs::create_dir_all`. #33707
Comments
apasel422
added
the
A-libs
label
May 18, 2016
alexcrichton
added
I-nominated
T-libs
labels
May 19, 2016
This comment has been minimized.
This comment has been minimized.
|
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? |
alexcrichton
removed
the
I-nominated
label
May 24, 2016
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
Yeah it should still work, we'd probably just want to add some more tests as well |
mgoszcz2
referenced this issue
Feb 7, 2017
Merged
Fix a bug where last part of the key is discarded and replaced with default filename #17
emk
added a commit
to emk/subtitles-rs-old
that referenced
this issue
Feb 13, 2017
steveklabnik
removed
the
A-libs
label
Mar 24, 2017
dpc
referenced this issue
Apr 20, 2017
Closed
Too much useless io in chunk_write due to create_dir_all() #95
This comment has been minimized.
This comment has been minimized.
rocallahan
commented
May 17, 2017
|
Can't this be closed now that #39799 is merged? |
dpc commentedMay 18, 2016
•
edited
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_allis a convenience function, and not one directly mapping to a posix fs operation. Ifstdlibprovides 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_allis 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 ifphexists but is not a directory.Think how many other Rust projects might have undetected race condition as they assumed the
create_dir_allwill do the right thing. Short googling already pointed other project that got bitten: https://github.com/droundy/bigbro/blob/464bfae81de4ad695a158315e3c75d6d21e382a2/src/lib.rs#L43