diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2021-04-14 12:02:37 -0400 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2021-04-16 11:16:15 -0400 |
commit | 5c21861b5d964c86bc33af30e83cdcb82e198c1b (patch) | |
tree | 3045d9a0a6edb50c12b4b85d0c21fb5b9f90dff9 | |
parent | 6be08f4b1d4f8d04f4b8a221eeed29e94c574407 (diff) | |
download | podman-5c21861b5d964c86bc33af30e83cdcb82e198c1b.tar.gz podman-5c21861b5d964c86bc33af30e83cdcb82e198c1b.tar.bz2 podman-5c21861b5d964c86bc33af30e83cdcb82e198c1b.zip |
Fix flake on failed podman-remote build
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: https://github.com/containers/podman/issues/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 <dwalsh@redhat.com>
-rw-r--r-- | pkg/api/handlers/compat/images_build.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 36785a362..b7c5bf2d6 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -376,12 +376,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")) } }() @@ -397,8 +402,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 { @@ -439,7 +442,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) |