Skip to content
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

fix(core): Handle removing non-empty directories and non-existing paths in cache #23279

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Exelord
Copy link

@Exelord Exelord commented May 9, 2024

Current Behavior

When running NX concurrently sometimes NX is trying to remove non-existing path (which have been already deleted by other process) or non-empty directories (which contains files created by other process but not yet removed)

To prevent race conditions, remove from fs-extra works in following way:

Removes a file or directory. The directory can have contents. If the path does not exist, silently does nothing.

Expected Behavior

Remove operations should work with non-existing paths as well as non-empty directories

Related Issue(s)

Fixes #22140

@Exelord Exelord requested a review from a team as a code owner May 9, 2024 18:38
@Exelord Exelord requested a review from xiongemi May 9, 2024 18:38
Copy link

vercel bot commented May 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview May 20, 2024 5:12pm

Copy link

nx-cloud bot commented May 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit fe2ca29. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx-cloud record -- nx format:check --base=0322b9804f3328b76acfa2848e52acf3d28cc55f --head=fe2ca299045caba8807ebf8edf40aa45545b1301
nx affected -t e2e-macos-ci --parallel=1 --base=0322b9804f3328b76acfa2848e52acf3d28cc55f --head=fe2ca299045caba8807ebf8edf40aa45545b1301
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@Exelord Exelord changed the title fix: Handle removing non-empty directories and non-existing paths fix(core): Handle removing non-empty directories and non-existing paths May 9, 2024
@Exelord Exelord changed the title fix(core): Handle removing non-empty directories and non-existing paths fix(core): Handle removing non-empty directories and non-existing paths in cache May 9, 2024
@FrozenPandaz
Copy link
Collaborator

FrozenPandaz commented May 9, 2024

Thank you so much for isolating the issue!

Hm, this removes the usage of our rust implementation of removing files where we also use a fs-extras type library.

https://github.com/nrwl/nx/blob/master/packages/nx/src/native/cache/file_ops.rs#L8

The rust one proved to be much faster so we should continue using that one and address the issue there.

@Exelord If you're familiar with Rust, we would appreciate if you continue looking into the issue. If not, no worries, you've been a great help already. @AgentEnder can take over from here.

@Exelord
Copy link
Author

Exelord commented May 10, 2024

Great! Please do take over. I have tried to use rust fs-extra but it does not work the way described, so it would require some native implementation which I cannot help with. While JS remove might be slower it does fix the issue, so I went with that as a quick fix.

Thank you :)

@Exelord
Copy link
Author

Exelord commented May 20, 2024

Small, update. As in other places, the remove errors have been ignored as OS still can throw lock errors while trying to remove files used by concurrent process. (there is no fix for that - OS intended, but the file will be scheduled for remove)

While its still using remove from fs-extra, it works now, which is faster than using rust's remove which throws.

@Eastonco
Copy link

Hey guys, Would love to see this merged. My enterprise team has been dealing with this issue for awhile now and would love to see a fix :) @AgentEnder Can you assist?

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.

Directory not empty (os error 66
4 participants