Refactor BuildWithResultHandler to simplify concurrency usage by jedevc · Pull Request #1504 · docker/buildx (original) (raw)
🛠️ Fixes #1497.
Using the error group concurrency primitive we can avoid needing to create a separate wait group.
This allows us to sidestep the issue described in #1497 (comment) where the wait group could be completed, but the build invocation functions had not terminated - if one of the functions was to terminate with an error, then it was possible to encounter a race condition, where the result handling code would begin executing, despite an error.
The refactor to use a separate error group which more elegantly handles the concept of function returns and errors, ensures that we can't encounter this issue.
For clarity, this fix is split in to three separate commits, the first two refactoring to simplify the fix, the final one the actual fix, to make the diffs easier to review.