Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/buildx/commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ func BakeCmd() *cobra.Command {
err = eg.Wait()

// Now wait for the printer to finish and flush all output
_ = printer.Wait()
for range projectIDs {
_ = printer.Wait()
}
Comment on lines +428 to +430
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change may cause a panic with 'negative WaitGroup counter' since printer.Wait() calls w.wg.Done() internally. Calling it multiple times (once per project ID) will decrement the counter beyond its initial value.

The solution should ensure that the number of Wait() calls matches the number of times the printer was added to the WaitGroup. Consider either:

  1. Tracking how many times the printer was added and calling Wait() exactly that many times, or
  2. Modifying the SharedPrinter.Wait() implementation to safely handle multiple calls

The current implementation of SharedPrinter.Wait() assumes it will be called exactly once per addition.

GitHub Flavored Markdown: No

Suggested change
for range projectIDs {
_ = printer.Wait()
}
// Only need to wait once for the printer to finish
_ = printer.Wait()

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


// Print save help and linter output after all project builds complete
for _, result := range buildResults {
Expand Down
6 changes: 2 additions & 4 deletions pkg/progresshelper/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func (w *SharedPrinter) Add() {

func (w *SharedPrinter) Wait() error {
w.wg.Done()
w.wg.Wait()

w.cancel()

lastPrinter := w.numPrinters.Add(-1) == 0

// The docker progress writer will only return an
Expand All @@ -62,6 +58,8 @@ func (w *SharedPrinter) Wait() error {
// Only the last printer will be the one to stop the docker printer as
// the docker printer closes channels.
if lastPrinter {
w.wg.Wait()
w.cancel()
_ = w.printer.Wait()
}

Expand Down
Loading