Repository navigation
fix(build): read bake's stderr to the end before waiting for it - #14335
Conversation
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
docker-agent
left a comment
There was a problem hiding this comment.
This review covers only the commits pushed since e7f8690.
Assessment: 🟢 APPROVE
The single changed line restores fmt.Errorf("failed to execute bake: %w", readErr) error wrapping in forwardBakeStatus, which was inadvertently dropped in the prior commit. This is the correct fix: it preserves error chain unwrappability (%w) and adds the diagnostic context string "failed to execute bake" so callers can identify the source of the I/O error. No bugs introduced.
b42b340 to
170b634
Compare
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The fix correctly resolves the race between reading bake's stderr and waiting for the process to exit — reading to EOF before calling cmd.Wait() is precisely what the os/exec documentation requires, and the regression test pins the mechanism reliably.
Lower-confidence findings (not posted inline)
-
[low]
pkg/compose/build_bake_test.go:566 — consumer goroutine may leak if an earlier assertion callst.Fatal(confidence: not scored — low severity, skipped verification)The goroutine that counts received status records sends its result to the unbuffered
receivedchannel. If any assertion before<-received(lines 568–572) fails and triggerst.Fatal/t.FailNow, the test function returns immediately, leaving the goroutine permanently blocked on the send. Usingreceived := make(chan int, 1)(capacity 1) would eliminate the risk without changing any other logic.
docker-agent
left a comment
There was a problem hiding this comment.
This review covers only the commits pushed since 170b6346ae37.
Assessment: 🟢 APPROVE
The single change — buffering the received channel with capacity 1 in TestWaitBakeKeepsTheEndOfTheStream — is correct and sufficient. The goroutine sends exactly one value to received after ch is closed, so a buffer of 1 guarantees the goroutine exits cleanly even if an assertion aborts the test via t.FailNow() before the <-received receive is reached, preventing a goroutine leak. No issues introduced by this change.
doBuildBake waited for the buildx process in a goroutine while reading its rawjson stderr stream. os/exec closes the pipe as soon as Wait sees the process exit, dropping whatever was not read yet: when the consumer of the solve statuses (the progress display) lags behind the process, the end of the stream is lost. That is where bake tells why it failed (the Dockerfile excerpt, then "failed to solve: ..."), so the build failed with exit code 1 but without its reason, or with it truncated. Read the stream to EOF first, as the os/exec documentation requires, then Wait. The os.ErrClosed case of the reader, which only existed to absorb the pipe being closed under it, goes away with the race. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1f1b41a to
a2e88f5
Compare
What this PR does, in one sentence
Stops
compose buildfrom sometimes losing the reason of a build failure: the end of buildx's output, where the error is, was dropped when the progress display lagged behind the process.Context
compose buildrunsdocker buildx bakeand reads its progress from the process's standard error, forwarding the solve statuses to the progress display and keeping the other lines, which are the error. The process was waited for in a goroutine while that stream was still being read, and Go closes the pipe as soon as it sees the process exit — what was not read yet is gone. When the display is slower than the process, which a loaded machine makes likely, the tail of the stream is lost: the build fails with exit code 1 but without the Dockerfile excerpt and thefailed to solve: …line that explain why, or with them cut in the middle.That is what a few end-to-end tests have been failing on intermittently, in the CI jobs of otherwise unrelated pull requests:
TestBuildPlatformsWithCorrectBuildxConfig/platform_not_supported_by_builderandTestBuildSSH/build_failed_with_ssh_default_valueexpect an error message on standard error and find the output cut right before it (in the failing run, the Dockerfile excerpt stops afterFROM alpine, with no final error line). The pattern dates from the introduction of the bake build.What the PR brings
The stream is now read to the end before the process is waited for, as the
os/execdocumentation requires, so the failure of a build always reaches the user with its reason. The case in the reader that only existed to absorb the pipe being closed under it is removed with the race, and a read error now stops the process instead of leaving it blocked on a stream nobody reads.A regression test runs a fake bake that writes a long stream of statuses then an error and exits at once, with a deliberately slow consumer: it fails deterministically without the fix (the error line is lost) and passes with it. I could not reproduce the failure of the end-to-end tests themselves on a quiet or a heavily loaded machine; the test pins the mechanism instead.
🤖 Generated with Claude Code