mirror of
https://github.com/moby/moby.git
synced 2026-07-12 10:35:14 +00:00
Before this change, it would fail to detect context errors, resulting in pullEndpoints clobbering the context error and changing it into a fallback error;029933578b/distribution/pull.go (L114-L119)While the context cancellation would still be handled, the error returned would be wrapped, causing calling code to no longer being able to detect it as context cancellation;029933578b/distribution/pull.go (L125)Context cancellation are now logged as "info" in daemon-logs, as they are not an error from the daemon's perspective; Before: DEBU[2025-01-18T14:59:10.079259676Z] pulling blob "sha256:8bb55f0677778c3027fcc4253dc452bc9c22de989a696391e739fb1cdbbdb4c2" ERRO[2025-01-18T14:59:10.564076135Z] Not continuing with pull after error: context canceled After: DEBU[2025-01-18T15:09:56.743045420Z] pulling blob "sha256:8bb55f0677778c3027fcc4253dc452bc9c22de989a696391e739fb1cdbbdb4c2" INFO[2025-01-18T15:09:57.390835628Z] Not continuing with pull after error error="context canceled" This package needs a big cleanup for context- and error-handling, as it's very messy, so these changes are only a short-term workaround. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package distribution // import "github.com/docker/docker/distribution"
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/docker/distribution/registry/api/errcode"
|
|
"github.com/docker/distribution/registry/client"
|
|
)
|
|
|
|
var errUnexpected = errors.New("some totally unexpected error")
|
|
|
|
var alwaysContinue = []error{
|
|
&client.UnexpectedHTTPResponseError{},
|
|
errcode.Errors{},
|
|
errUnexpected,
|
|
// nested
|
|
errcode.Errors{errUnexpected},
|
|
}
|
|
|
|
var continueFromMirrorEndpoint = []error{
|
|
imageConfigPullError{},
|
|
errcode.Error{},
|
|
// nested
|
|
errcode.Errors{errcode.Error{}},
|
|
}
|
|
|
|
func TestContinueOnError_NonMirrorEndpoint(t *testing.T) {
|
|
for _, err := range alwaysContinue {
|
|
if !continueOnError(err, false) {
|
|
t.Errorf("Should continue from non-mirror endpoint: %T: '%s'", err, err.Error())
|
|
}
|
|
}
|
|
|
|
for _, err := range continueFromMirrorEndpoint {
|
|
if continueOnError(err, false) {
|
|
t.Errorf("Should only continue from mirror endpoint: %T: '%s'", err, err.Error())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestContinueOnError_MirrorEndpoint(t *testing.T) {
|
|
var errs []error
|
|
errs = append(errs, alwaysContinue...)
|
|
errs = append(errs, continueFromMirrorEndpoint...)
|
|
for _, err := range errs {
|
|
if !continueOnError(err, true) {
|
|
t.Errorf("Should continue from mirror endpoint: %T: '%s'", err, err.Error())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestContinueOnError_NeverContinue(t *testing.T) {
|
|
neverContinue := []error{
|
|
errors.New(strings.ToLower(syscall.ESRCH.Error())), // No such process
|
|
context.Canceled,
|
|
context.DeadlineExceeded,
|
|
}
|
|
|
|
for _, isMirrorEndpoint := range []bool{true, false} {
|
|
for _, err := range neverContinue {
|
|
if continueOnError(err, isMirrorEndpoint) {
|
|
t.Errorf("Should never continue: %T: '%s'", err, err.Error())
|
|
}
|
|
}
|
|
}
|
|
}
|