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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/vite/src/node/config.ts
Expand Up @@ -1039,7 +1039,11 @@ async function loadConfigFromBundledFile(
try {
return (await dynamicImport(fileUrl)).default
} finally {
fs.unlinkSync(fileNameTmp)
try {
fs.unlinkSync(fileNameTmp)
} catch {
// already removed if this function is called twice simultaneously
}
Comment on lines +1042 to +1046
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.

}
}
// for cjs, we can register a custom loader via `_require.extensions`
Expand Down