Skip to content

Commit

Permalink
Fix flake on failed podman-remote build
Browse files Browse the repository at this point in the history
We have a race condition where podman build can fail
but still return an exit code of 0.  This PR ensures
that as soon as the build fails, the failed flag is set
eliminating the race.

Fixes: containers#10029

[NO TESTS NEEDED] Tests of failed builds are already in place, and
the elimination of the race should be enough.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan authored and jmguzik committed Apr 26, 2021
1 parent d3b5c3f commit 8e33559
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
buildOptions.Timestamp = &ts
}

var (
imageID string
failed bool
)

runCtx, cancel := context.WithCancel(context.Background())
var imageID string
go func() {
defer cancel()
imageID, _, err = runtime.Build(r.Context(), buildOptions, query.Dockerfile)
if err != nil {
failed = true
stderr.Write([]byte(err.Error() + "\n"))
}
}()
Expand All @@ -483,8 +488,6 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
flush()

var failed bool

body := w.(io.Writer)
if logrus.IsLevelEnabled(logrus.DebugLevel) {
if v, found := os.LookupEnv("PODMAN_RETAIN_BUILD_ARTIFACT"); found {
Expand Down Expand Up @@ -525,7 +528,6 @@ loop:
}
flush()
case e := <-stderr.Chan():
failed = true
m.Error = string(e)
if err := enc.Encode(m); err != nil {
logrus.Warnf("Failed to json encode error %v", err)
Expand Down

0 comments on commit 8e33559

Please sign in to comment.