-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Deal with some race conditions in mkpath #13794
Conversation
The Travis build is failing when it tries to (I think) download and install the dependencies (https://travis-ci.org/JuliaLang/julia/jobs/87760084#L3123 and next 50 lines). I don't think this is an issue from my commit (although of course, one can never be sure). Is there a way to re-run Travis? |
Yep, good reading of the log, I restarted it and looks fine. I'm not sure whether that type assertion (p.s. good to see another contributor from Berkeley - there's a Bay Area Julia Users' meetup on Thursday, you should come) |
Fair enough. I'm still learning some of the syntax. Is there a way (other than using I would have just used And thanks for the invite to the meetup. I'm busy tomorrow but I'll check the calendar for future meetings. |
I don't think we have a dispatch-based catch implemented, it would be cool if it worked that way though.
Might be a bug that we get an
|
Hm, I guess I'll search through the issues to see if that already exists or if people have already decided it's not a good idea. And I'll fix my code and push again. |
Also the |
Apparently the syntax I used was proposed and rejected in favor if |
Time to test? |
# does in fact exist, then ignore the error. Else re-throw it. | ||
catch err | ||
# isdir comes first because I figure it will return false more often | ||
# than isa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isdir
is a fairly expensive syscall while isa
is essentially a free pointer comparison. (although this is the failure case just after trying an even more expensive mkdir
syscall, so the relative performance probably isn't too important)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second look, it seems that the only error mkdir
ever throws is a SystemError
, so the isa
call is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only error thrown directly, though i wonder whether any nested calls at deeper levels would throw anything else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out an instance where that would happen. Of course that's no guarantee. That being said, which of the following is our desired behavior:
- Suppress the "file exists" system error and continue making new directories
- or, suppress any error as long as directories continue to be created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the former. Suppressing all errors without checking the reason for them too carefully can be dangerous and conceal bugs in deeper layers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I pushed a new commit taking that into account.
I updated the |
Can you squash the commits? I think this is good to merge after that, any objections? |
Although mkpath checks to see which parent directories need to be created, there is a race condition from the time of that check and the actual creation of directories. In the event another process creates one of those directories during that time, this commit will suppress the mkdir error due to the file already existing. Addresses issue JuliaLang#13094. I put the type check before the check for new directory existence since the type check is faster.
e7d0c9b
to
9bd80c2
Compare
Travis and AppVeyor are happy with the final squashed commit. |
Deal with some race conditions in mkpath
From my commit message:
Although mkpath checks to see which parent directories need to be
created, there is a race condition from the time of that check and the
actual creation of directories. In the event another process creates one
of those directories during that time, this commit will suppress the
mkdir error due to the file already existing. Addresses issue #13094.
Additionally:
As mentioned on the issue thread, it's impossible to prevent all race conditions in this situation, but I think this is a reasonable place to stop. If some other process creates one of the intended directories, then great, no error should occur. On the other hand, if the other process deletes one of the directories, then an error is a good thing in my opinion.