From 7953c57d8870985a1e354ccf0652e170b20c486c Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 8 May 2024 10:07:11 -0400 Subject: [PATCH] copierWithSubprocess(): try to capture stderr on io.ErrClosedPipe When we get a tried-to-write-to-closed-pipe error while encoding something for a coprocess, try to capture error output from the coprocess and add it to the error message, to hopefully catch a flake we're seeing in CI. Signed-off-by: Nalin Dahyabhai --- copier/copier.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/copier/copier.go b/copier/copier.go index babab388866..0dfdca39705 100644 --- a/copier/copier.go +++ b/copier/copier.go @@ -18,6 +18,7 @@ import ( "sync" "syscall" "time" + "unicode" "github.com/containers/image/v5/pkg/compression" "github.com/containers/storage/pkg/archive" @@ -633,6 +634,15 @@ func copierWithSubprocess(bulkReader io.Reader, bulkWriter io.Writer, req reques if err2 := cmd.Process.Kill(); err2 != nil { return nil, fmt.Errorf("killing subprocess: %v; %s: %w", err2, step, err) } + if errors.Is(err, io.ErrClosedPipe) || errors.Is(err, syscall.EPIPE) { + err2 := cmd.Wait() + if errorText := strings.TrimFunc(errorBuffer.String(), unicode.IsSpace); errorText != "" { + err = fmt.Errorf("%s: %w", errorText, err) + } + if err2 != nil { + return nil, fmt.Errorf("waiting on subprocess: %v; %s: %w", err2, step, err) + } + } return nil, fmt.Errorf("%v: %w", step, err) } if err = encoder.Encode(req); err != nil {