build: parallelize forced reference evaluation#3696
Open
tonistiigi wants to merge 1 commit intodocker:masterfrom
Open
build: parallelize forced reference evaluation#3696tonistiigi wants to merge 1 commit intodocker:masterfrom
tonistiigi wants to merge 1 commit intodocker:masterfrom
Conversation
Use an errgroup helper to evaluate result refs concurrently during forced evaluation, and fail fast on the first evaluation error. This mitigates current case in bake where chained targets with a multi-platform build could miss secrets and other session properties. The outline for the issue case: - Base target is solved but only lazily and not really loaded/tracked in build graph yet. - Child targets are loaded, base target waits. - Evaluate is called for base stage (because it might be missing result condition), child stage is processed as build result. This happens in parallel. - Because `Evaluate()` was called synchronously, it may have not been called yet for the second platform while the child target already needs to run `RUN --mount=type=secret`. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
crazy-max
approved these changes
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix #3543
@nicocrm
Use an errgroup helper to evaluate result refs concurrently during forced evaluation, and fail fast on the first evaluation error.
This mitigates the current case in Bake where chained targets with a multi-platform build could miss secrets and other session properties.
The outline for the issue case:
Evaluate()was called synchronously, it may not have been called yet for the second platform while the child target already needs to runRUN --mount=type=secret.This isn't a completely proper fix, but in practice, it should make the request timings so that the wrong order of steps does not occur. There is still misalignment that buildx seems to assume that after non-evaluated solve result is returned, the associated LLB is reference counted for the duration of the build request. While in reality, the lazy solve just returns the handle to the LLB definition in the request without attempting to load it into the build graph at all. Possible fixes for this would be to make BuildKit load the LLB but not trigger graph evaluation even on lazy solve, or add something new in the gateway API like
ref.Prepare()that does the same thing explicitly.