-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[node-modules] Fixes race between mkdirp
and remove
#1108
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
Conversation
…ng all `remove` first.
…uring all the operations
a6358a5
to
b78ca4d
Compare
@larixer I saw that you pinged me but I don't remember where the race condition came up 😅 |
@nicolo-ribaudo I have pinged you, to keep you in the loop, that the problem has been spotted, that might affect you. |
Oh ok, thank you! Btw, I haven't found any recent new issue with |
deleteList.add(curLocation); | ||
// If previous install had inner node_modules folder, we should explicitely list it for | ||
// `removeDir` to delete it, but we need to delete it first, so we add it to inner delete list | ||
if (prevNode && prevNode.children.has(NODE_MODULES)) | ||
innerDeleteList.add(ppath.join(curLocation, NODE_MODULES)); |
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.
Wouldn't it be enough to process the delete list in the reverse insertion order?
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.
No, since we run all delete operations in parallel
What's the problem this PR addresses?
We have observed one case of a race condition in
node-modules
linker betweenmkdirp
andremove
operations, during persisting of packages intonode_modules
The error message looks like:
How did you fix it?
I have tweaked the order of operations, so that all
remove
's were executed first and only after they had been finished all the other file operations were performed.Another change in this PR is simplification of the code for inner
node_modules
directories handling for the cases likenode_modules/foo/node_modules/bar
. In all theaddModule
,deleteModule
,copyDir
,removeDir
operations that targetnode_modules/foo
we now do not remove/copynode_modules/foo/node_modules
and to actually deletenode_modules/foo/node_modules
, theremoveDir('
node_modules/foo/node_modules')
should be called. All the innernode_modules
deletions are performed at the very beginning of linking before all other copying/cloning operations. This way the code is seriously simplified.cc @nicolo-ribaudo