Merge pull request #2043 from aaronlehmann/retry-on-5xx

Add retry on image push 5xx errors
v0.9
Tõnis Tiigi 2021-03-29 13:03:16 -07:00 committed by GitHub
commit 216f9bdb66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 2 deletions

View File

@ -65,7 +65,7 @@ func CopyChain(ctx context.Context, ingester content.Ingester, provider content.
handlers := []images.Handler{ handlers := []images.Handler{
images.ChildrenHandler(provider), images.ChildrenHandler(provider),
filterHandler, filterHandler,
retryhandler.New(remotes.FetchHandler(ingester, &localFetcher{provider}), nil), retryhandler.New(remotes.FetchHandler(ingester, &localFetcher{provider}), func(_ []byte) {}),
} }
if err := images.Dispatch(ctx, images.Handlers(handlers...), nil, desc); err != nil { if err := images.Dispatch(ctx, images.Handlers(handlers...), nil, desc); err != nil {

View File

@ -101,7 +101,7 @@ func Config(ctx context.Context, str string, resolver remotes.Resolver, cache Co
children := childrenConfigHandler(cache, platform) children := childrenConfigHandler(cache, platform)
handlers := []images.Handler{ handlers := []images.Handler{
retryhandler.New(remotes.FetchHandler(cache, fetcher), nil), retryhandler.New(remotes.FetchHandler(cache, fetcher), func(_ []byte) {}),
children, children,
} }
if err := images.Dispatch(ctx, images.Handlers(handlers...), nil, desc); err != nil { if err := images.Dispatch(ctx, images.Handlers(handlers...), nil, desc); err != nil {

View File

@ -133,6 +133,7 @@ func (sw *streamWriter) Close() error {
func LoggerFromContext(ctx context.Context) func([]byte) { func LoggerFromContext(ctx context.Context) func([]byte) {
return func(dt []byte) { return func(dt []byte) {
pw, _, _ := progress.FromContext(ctx) pw, _, _ := progress.FromContext(ctx)
defer pw.Close()
pw.Write(identity.NewID(), client.VertexLog{ pw.Write(identity.NewID(), client.VertexLog{
Stream: stderr, Stream: stderr,
Data: []byte(dt), Data: []byte(dt),

View File

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/containerd/containerd/images" "github.com/containerd/containerd/images"
remoteserrors "github.com/containerd/containerd/remotes/errors"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -48,6 +49,14 @@ func New(f images.HandlerFunc, logger func([]byte)) images.HandlerFunc {
} }
func retryError(err error) bool { func retryError(err error) bool {
// Retry on 5xx errors
var errUnexpectedStatus remoteserrors.ErrUnexpectedStatus
if errors.As(err, &errUnexpectedStatus) &&
errUnexpectedStatus.StatusCode >= 500 &&
errUnexpectedStatus.StatusCode <= 599 {
return true
}
if errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.EPIPE) { if errors.Is(err, io.EOF) || errors.Is(err, syscall.ECONNRESET) || errors.Is(err, syscall.EPIPE) {
return true return true
} }