Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue
See #3257.
When running multiple pipenv processes simultaneously, they may both attempt to use 'mkdir_p' at the same time, which can cause one of the pipenv processes to crash when it tries to create a directory that already exists. This is a classic TOCTOU bug that has bitten many a piece of software.
I personally hit this in my continuous integration setup where I invoke
pipenv
multiple times, potentially in parallel, and see crashes such as this:The root cause is that two
pipenv
processes are racing to create the new directory subtree rooted at/home/travis/.local/share/virtualenvs
, one of them wins, and the other crashes.The fix
I fixed
mkdir_p
to ignoreOSError
s that come fromos.mkdir
if theOSError
's errno isEEXIST
. This makes sense, because the objective ofmkdir_p
is to create a tree of directories, and so truly getting an error that the directory exists already isn't an error at all and actually is a success.The checklist
news/
directory to describe this fix with the extension.bugfix
,.feature
,.behavior
,.doc
..vendor
. or.trivial
(this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.