Skip to content

Commit

Permalink
copierWithSubprocess(): try to capture stderr on io.ErrClosedPipe
Browse files Browse the repository at this point in the history
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 <nalin@redhat.com>
  • Loading branch information
nalind committed May 13, 2024
1 parent 9907ec6 commit 3fb60f0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions copier/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"sync"
"syscall"
"time"
"unicode"

"github.com/containers/image/v5/pkg/compression"
"github.com/containers/storage/pkg/archive"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 3fb60f0

Please sign in to comment.