-
Notifications
You must be signed in to change notification settings - Fork 227
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
Race condition in concurrent pub git clone #3404
Comments
It's not entirely clear what is going wrong here. If someone wants to create a minimal example using only If we know for sure what bits fail, we can try to make a solution. One option is cloning to a temporary folder and moving atomically, but this has a tendency to cause problems for users on Windows anti-virus software installed. It also possible we should make a temporary folder + move and copy if moving fails. |
Think I tracked it down to two issues: #3455 (dart run does not refresh dependencies if the PUB_CACHE has changed) |
Does not resolve the issue.
After pulling repo, the package
flutter pub get fails:
|
Deleting |
I hadn't discovered the |
I think it is pretty clear what is going on. Two pub-get processes discover that the same git-dependency is not cloned into the cache, and the both initiate the cloning process, and one steps the other on the toes. I believe the following script reproduces very reliably:
|
…tion When running the command "flutter pub get," the plugins are stored in the pub-cache directory along with their sha256sum hashes. The default location of the pub-cache directory is current $(HOST_DIR)/share/flutter/sdk/.pub-cache, which is not an acceptable choice by default because every plugin is re-downloaded during every build of a flutter application either during a new build or when building with the per-package-directory option enabled. Furthermore, keeping the pub-cache in its current location prevents users from committing the pub-cache directory to git for faster rebuilds of a Buildroot-based system, as users cannot store the pub-cache for later use. To fix the above issue completely, the following two changes must occur: - Change the hard-coded Flutter pub-cache location to $(DL_DIR)/br-flutter-pub-cache. - Remove the `rm -rf $(HOST_FLUTTER_SDK_BIN_SDK)/.pub-cache` and the associated comment about why the build system removes the .pub-cache directory. After further research, the help text of the precache command reads, "Populate the Flutter tool's cache of binary artifacts." The current reasoning listed in the comments is not accurate for a the following reasons: 1. We do not want to remove their directory if users already have a pub cache they have symlinked to. 2. If the flutter-sdk-bin package previously set up the pub-cache, then the pub-cache directory is set up with the options we want, and there is no reason to remove the pub-cache directory. Note that upstream considers it safe to have multiple instances of readers/writers to the pub cache concurently, which is a situation that can happen when two flutter-based pacakges are going to be built in parallel. There have been reports upstream [0] [1] [2] where concurrency was an issue, and they have always been fixed [3] [4] (or considered fixed already). So we can assune that, if the conncurrent ccess to the shared pub-cache causes issues, that will be an upstream bug that will get solved. If that turns out to be an unsolvable problem, we'll still have the option to run the pub-get commands under flock. [0] dart-lang/pub#1178 [1] dart-lang/pub#3404 [2] dart-lang/pub#3420 [3] dart-lang/pub#1178 (comment) [4] dart-lang/pub#1178 (comment) Signed-off-by: Adam Duskett <[email protected]> [[email protected]: add blurb about concurrent access] Signed-off-by: Yann E. MORIN <[email protected]>
…tion When running the command "flutter pub get," the plugins are stored in the pub-cache directory along with their sha256sum hashes. The default location of the pub-cache directory is current $(HOST_DIR)/share/flutter/sdk/.pub-cache, which is not an acceptable choice by default because every plugin is re-downloaded during every build of a flutter application either during a new build or when building with the per-package-directory option enabled. Furthermore, keeping the pub-cache in its current location prevents users from committing the pub-cache directory to git for faster rebuilds of a Buildroot-based system, as users cannot store the pub-cache for later use. To fix the above issue completely, the following two changes must occur: - Change the hard-coded Flutter pub-cache location to $(DL_DIR)/br-flutter-pub-cache. - Remove the `rm -rf $(HOST_FLUTTER_SDK_BIN_SDK)/.pub-cache` and the associated comment about why the build system removes the .pub-cache directory. After further research, the help text of the precache command reads, "Populate the Flutter tool's cache of binary artifacts." The current reasoning listed in the comments is not accurate for a the following reasons: 1. We do not want to remove their directory if users already have a pub cache they have symlinked to. 2. If the flutter-sdk-bin package previously set up the pub-cache, then the pub-cache directory is set up with the options we want, and there is no reason to remove the pub-cache directory. Note that upstream considers it safe to have multiple instances of readers/writers to the pub cache concurently, which is a situation that can happen when two flutter-based pacakges are going to be built in parallel. There have been reports upstream [0] [1] [2] where concurrency was an issue, and they have always been fixed [3] [4] (or considered fixed already). So we can assune that, if the conncurrent ccess to the shared pub-cache causes issues, that will be an upstream bug that will get solved. If that turns out to be an unsolvable problem, we'll still have the option to run the pub-get commands under flock. [0] dart-lang/pub#1178 [1] dart-lang/pub#3404 [2] dart-lang/pub#3420 [3] dart-lang/pub#1178 (comment) [4] dart-lang/pub#1178 (comment) Signed-off-by: Adam Duskett <[email protected]> [[email protected]: add blurb about concurrent access] Signed-off-by: Yann E. MORIN <[email protected]> (cherry picked from commit 3780925) Signed-off-by: Peter Korsgaard <[email protected]>
Environment
pub version
orflutter pub version
:Problem
I have a monorepo with several packages, using melos. I upgraded to melos 2.0 which introduced concurrent pub getting. The problem is several of my packages share the same external git dependency and the very first time I run
melos bootstrap
in a fresh repository it throws the following error:When i run
melos bootstrap
a second time, it finishes without an error. It seems like there is some kind of race condition with the pub command related to this shared git dependency which causes the pub gets to fail the first time but work the second time.Expected behavior
Should be able to pub get in parallel for git dependencies.
Actual behavior
I have to do it twice to succeed.
--trace output
The text was updated successfully, but these errors were encountered: