-
Notifications
You must be signed in to change notification settings - Fork 800
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
bug: Copy task runs in parallel to build tasks creating a race condition #5592
bug: Copy task runs in parallel to build tasks creating a race condition #5592
Comments
Hey @mt3o 👋 While I can see how this could be an issue, some of these reproduction steps are too vague for us to be able to move forward with this. While we don't want you to share any work you're not permitted to, we do need some type of reproduction case here to clarify things like:
Otherwise, we could spend quite a bit of time building something that doesn't actually reproduce the problem you're seeing here. One possibility, would be to use the stencil component starter ( Another would be to use the Ionic Framework (built with Stencil) and try to use it and its stencil config to try to reproduce the problem. |
Thanks for the issue! This issue has been labeled as Please reproduce this issue in an Stencil starter component library and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed. If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue. For a guide on how to create a good reproduction, see our Contributing Guide. |
Hi
|
I finally created the repo to present the problem so that you can replicate. https://github.com/mt3o/stencil-race-condition-between-copy-and-build https://stackblitz.com/~/github.com/mt3o/stencil-race-condition-between-copy-and-build Please verify |
Hey @mt3o, Thanks for the repro! Can you provide instructions for using it to verify this bug? I see a Thanks! |
@mt3o thanks, I've ingested this issue into our backlog. At this point I can't provide any estimate as to when we get the chance to look into it. We appreciate any help on the issue and are available for questions as they arise. |
The fix would be, in file https://github.com/ionic-team/stencil/blob/main/src/compiler/output-targets/index.ts#L30 to alter the block: await Promise.all([
//outputCopy(config, compilerCtx, buildCtx), //remove this one
outputCollection(config, compilerCtx, buildCtx, changedModuleFiles),
outputCustomElements(config, compilerCtx, buildCtx),
outputHydrateScript(config, compilerCtx, buildCtx),
outputLazyLoader(config, compilerCtx),
outputLazy(config, compilerCtx, buildCtx),
]);
//and call it after compilation is done here, so that all files are already in place
await outputCopy(config, compilerCtx, buildCtx)
await outputWww(config, compilerCtx, buildCtx); |
@mt3o thanks, mind raising a PR for this? The team would greatly appreciate any help. |
I've raised a PR for this in #5902 |
Prerequisites
Stencil Version
4.13.0
Current Behavior
When building with stencil, when the copy task is issued here:
https://github.com/ionic-team/stencil/blob/main/src/compiler/output-targets/index.ts#L30
there is
Promise.all
calling all tasks, including copy tasks, and regular building tasks. When the build (compilation, regular targets) takes longer, copy task is executed first, trying to copy non-existing directories. It's a race condition between compilation and copying.I have problems replicating the issue with a smaller repo, and obviously, I can't share my work project. I'm guessing the issue happens only in big projects, or with poor hardware, as it's a race it depends on the performance.
For me - the workaround is to either create empty directories first (risking incomplete build), or not use copy-task at all, and instead copy files in standalone CI/CD script.
On developer machine, with watch mode, the problem is nearly nonexistent, as there are some files in /dist all the time. If something doesn't work, devs just restart the build script and then it goes smoothly. Such behavior in CI/CD is difficult to achieve.
Expected Behavior
Please consider moving
await outputCopy(config, compilerCtx, buildCtx),
after thePromise.all
and before the www target. This should solve the race problem.System Info
Steps to Reproduce
Set up a big repo with complex components,
Add lots of targets to be compiled
Set www target to be built
Have all targets be copied into www
run
npx stencil build
Stencil runs all tasks as in Promise.all call, copy ends after build tasks are over, compilation breaks with error that some dirs don't exist in /dist.
Code Reproduction URL
no url :(
Additional Information
The log is as follows, it's that the clear copy task is ending before the build tasks are finished. So I'm concluding that moving the copy task out of
Promise.all
will solve the problem - because the copy task will be executed only after all build tasks are done.The text was updated successfully, but these errors were encountered: