build: wait from child targets to complete before session release #2108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When targets in bake are chained with named build contexts we need to wait for the second target to complete the solve before the session from first build can be released. Otherwise, the first build could already release the definition from the buildkit graph before second build starts. Normally this would not be a problem because the steps from first build should get a direct cache match but there are some edge cases with local sources where another build can take ownership of the shared destination directory and then for specific graph layout BuildKit solver would find that it can possibly match cache if it would recompute content checksums for the local source, causing it to be repulled again via session.
Because
Evaluate()
is called manually in this patch it might cause a small performance regression in some edge cases because all targets that are used in build contexts need to wait for the childSolve()
requests to return before they can export their outputs. Additionally, there is an unlikely case that the exporter like registry does not need to pull the layer at all ifEvaluate
would not be called. To fix this, buildkit API side change would be needed that separates calling exporter and releasing from build graph to separate steps.