fix(optimizer): use temp dirs to ensure content of deps cache dir is consistent#12592
fix(optimizer): use temp dirs to ensure content of deps cache dir is consistent#12592dominikg wants to merge 3 commits intovitejs:mainfrom
Conversation
|
|
|
to avoid buildup of leftover temp directories, vite could delete all |
|
I would like us to try the overwrite approach first and see how it works in the wild. We had a lot of issues with the delete-then-rename scheme in the past year and I think we will end up encountering similar problems with the rename-then-rename-(then-delete-in-the-background). I will be sending another PR to use the result we have in memory instead of waiting for write-then-read the optimized deps, so we can do the commit in the background. I think the current method will give us fewer issues compared to having many directories. |
|
this is about ensuring content of deps cache on disk being consistent, not really about speed of rereading it. even for async commit you'll want to ensure that deps dir is not left in a half overwritten state if a process is terminated at any given point. |
|
it uses timestamp+random with 10 retries to avoid collisions even with concurrent processes, though these would still end up in a last to finish wins situation, so ultimately we'd need some semaphore or other method to resolve parallel commits by different processes |
Reasoning:
writing and removing files in the cache dir itself risks leaving a broken state when user aborts the process.
This PR changes it by writing to a temp directory first, and then uses 2 renameSync calls to replace the content.
/deps_temp_xxxx/depsto/deps_remove_yyyy/deps_temp_xxxto/deps/deps_remove_yyyyDescription
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).