summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2021-04-14 15:55:09 -0400
committerMatthew Heon <mheon@redhat.com>2021-04-16 11:16:36 -0400
commitfc99c7d0a3c9cfaec0658d552a5e43cda275ba55 (patch)
treeb6af926acecda9e66442d32fde646daa764cbf4d
parent5c21861b5d964c86bc33af30e83cdcb82e198c1b (diff)
downloadpodman-fc99c7d0a3c9cfaec0658d552a5e43cda275ba55.tar.gz
podman-fc99c7d0a3c9cfaec0658d552a5e43cda275ba55.tar.bz2
podman-fc99c7d0a3c9cfaec0658d552a5e43cda275ba55.zip
Fix flake on failed podman-remote build : try 2
This time we are checking if the function actually succeeded, otherwise we will report an error. Also if we did not get the id, report unexpected failure. [NO TESTS NEEDED] Still no good way to test this, but manually. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
-rw-r--r--pkg/api/handlers/compat/images_build.go10
-rw-r--r--pkg/bindings/images/build.go16
2 files changed, 20 insertions, 6 deletions
diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go
index b7c5bf2d6..5b8741e89 100644
--- a/pkg/api/handlers/compat/images_build.go
+++ b/pkg/api/handlers/compat/images_build.go
@@ -378,15 +378,16 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
var (
imageID string
- failed bool
+ success bool
)
runCtx, cancel := context.WithCancel(context.Background())
go func() {
defer cancel()
imageID, _, err = runtime.Build(r.Context(), buildOptions, query.Dockerfile)
- if err != nil {
- failed = true
+ if err == nil {
+ success = true
+ } else {
stderr.Write([]byte(err.Error() + "\n"))
}
}()
@@ -448,7 +449,8 @@ loop:
}
flush()
case <-runCtx.Done():
- if !failed {
+ flush()
+ if success {
if !utils.IsLibpodRequest(r) {
m.Stream = fmt.Sprintf("Successfully built %12.12s\n", imageID)
if err := enc.Encode(m); err != nil {
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index 17095b84b..06aa838db 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -304,6 +304,7 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
re := regexp.MustCompile(`[0-9a-f]{12}`)
var id string
+ var mErr error
for {
var s struct {
Stream string `json:"stream,omitempty"`
@@ -311,11 +312,21 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
}
if err := dec.Decode(&s); err != nil {
if errors.Is(err, io.EOF) {
- return &entities.BuildReport{ID: id}, nil
+ if mErr == nil && id == "" {
+ mErr = errors.New("stream dropped, unexpected failure")
+ }
+ break
}
s.Error = err.Error() + "\n"
}
+ select {
+ case <-response.Request.Context().Done():
+ return &entities.BuildReport{ID: id}, mErr
+ default:
+ // non-blocking select
+ }
+
switch {
case s.Stream != "":
stdout.Write([]byte(s.Stream))
@@ -323,11 +334,12 @@ func Build(ctx context.Context, containerFiles []string, options entities.BuildO
id = strings.TrimSuffix(s.Stream, "\n")
}
case s.Error != "":
- return nil, errors.New(s.Error)
+ mErr = errors.New(s.Error)
default:
return &entities.BuildReport{ID: id}, errors.New("failed to parse build results stream, unexpected input")
}
}
+ return &entities.BuildReport{ID: id}, mErr
}
func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {