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(config): try catch unlink after load #9577

Merged
merged 1 commit into from
Aug 8, 2022
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Aug 8, 2022

Description

While trying to run VitePress build on another project, there is a possibility for the bundled config to be called at the same time (same Date.now) based on this build code.

This sometimes cause Error: ENOENT: no such file or directory, unlink '/Users/bjorn/Work/oss/blas/vite.config.js.timestamp-1659938739266.mjs. This PR wraps the unlink in a try catch which works reliably for me.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added the p2-nice-to-have Not breaking anything but nice to have (priority) label Aug 8, 2022
Comment on lines +1042 to +1046
try {
fs.unlinkSync(fileNameTmp)
} catch {
// already removed if this function is called twice simultaneously
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This could explain the flakiness we experienced after the file name scheme change. I think there may not be possible to get a race condition between writing the file and doing the dynamic import, so this fix should work. Let's merge this one for now.

But maybe we should directly make sure we generate a unique name? Looks like we don't have a way to do UUIDs right now, so we could use a simple scheme as we do here

plus the current timestamp. I'm not sure if it is needed though, reusing the same file looks ok to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this should now work fine too as it's not possible for two simultaneous call to have one unlinking first before dynamic importing. Though I'd agree that a unique name would be a lot safer if we implement one day.

@patak-dev patak-dev merged commit d35a1e2 into main Aug 8, 2022
@patak-dev patak-dev deleted the config-safe-unlink branch August 8, 2022 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants