Skip to content

[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

Merged
merged 3 commits into from
Mar 23, 2020
Merged

Conversation

larixer
Copy link
Member

@larixer larixer commented Mar 23, 2020

What's the problem this PR addresses?

We have observed one case of a race condition in node-modules linker between mkdirp and remove operations, during persisting of packages into node_modules

The error message looks like:

Error: While persisting /D:/a/berry/berry/.yarn/cache/@emotion-hash-npm-0.7.1-cc52d429a7-2.zip/node_modules/@emotion/hash -> /D:/a/berry/berry/node_modules/@emotion/serialize/node_modules/@emotion/hash ENOENT: no such file or directory, mkdir 'D:\a\berry\berry\node_modules\@emotion\serialize\node_modules'

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 like node_modules/foo/node_modules/bar. In all the addModule, deleteModule, copyDir, removeDir operations that target node_modules/foo we now do not remove/copy node_modules/foo/node_modules and to actually delete node_modules/foo/node_modules, the removeDir('node_modules/foo/node_modules') should be called. All the inner node_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

@larixer larixer requested a review from arcanis March 23, 2020 11:19
@larixer larixer added the in progress Features claimed by a contributor label Mar 23, 2020
@larixer larixer force-pushed the nm-fix-mkdirp-race branch from a6358a5 to b78ca4d Compare March 23, 2020 13:31
@larixer larixer removed the in progress Features claimed by a contributor label Mar 23, 2020
@nicolo-ribaudo
Copy link
Contributor

@larixer I saw that you pinged me but I don't remember where the race condition came up 😅

@larixer
Copy link
Member Author

larixer commented Mar 23, 2020

@nicolo-ribaudo I have pinged you, to keep you in the loop, that the problem has been spotted, that might affect you.

@nicolo-ribaudo
Copy link
Contributor

nicolo-ribaudo commented Mar 23, 2020

Oh ok, thank you! Btw, I haven't found any recent new issue with node-modules neither on Linux, on Windows or in WSL.

Comment on lines +690 to +694
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));
Copy link
Member

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?

Copy link
Member Author

@larixer larixer Mar 23, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants