Merge pull request #71179 from idealhack/fix-cancel-functions

Call cancel functions to avoid context leaks

Kubernetes-commit: 819cfed09aac9270f2daa4dd07d62d2ac1736c6c
This commit is contained in:
Kubernetes Publisher 2018-12-18 23:35:35 -08:00
commit 749453644f
2 changed files with 61 additions and 54 deletions

102
Godeps/Godeps.json generated
View File

@ -404,207 +404,207 @@
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/fuzzer",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip", "ImportPath": "k8s.io/apimachinery/pkg/api/apitesting/roundtrip",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/equality", "ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/errors", "ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/meta", "ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/api/resource", "ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1", "ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion", "ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams", "ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/fields", "ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/labels", "ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime", "ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema", "ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning", "ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/selection", "ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/types", "ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/cache", "ImportPath": "k8s.io/apimachinery/pkg/util/cache",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/clock", "ImportPath": "k8s.io/apimachinery/pkg/util/clock",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/diff", "ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/errors", "ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/framer", "ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy", "ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr", "ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/json", "ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch", "ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/naming", "ImportPath": "k8s.io/apimachinery/pkg/util/naming",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/net", "ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand", "ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime", "ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/sets", "ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch", "ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation", "ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field", "ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/wait", "ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml", "ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/version", "ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/pkg/watch", "ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect", "ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "57dc7e687b5426ecb5df4cabdcdce30fddb74f22" "Rev": "4d029f0333996cf231080e108e0bd1ece2a94d9f"
}, },
{ {
"ImportPath": "k8s.io/klog", "ImportPath": "k8s.io/klog",

View File

@ -53,7 +53,9 @@ func TestUntil(t *testing.T) {
func(event watch.Event) (bool, error) { return event.Type == watch.Modified, nil }, func(event watch.Event) (bool, error) { return event.Type == watch.Modified, nil },
} }
ctx, _ := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...) lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...)
if err != nil { if err != nil {
t.Fatalf("expected nil error, got %#v", err) t.Fatalf("expected nil error, got %#v", err)
@ -80,7 +82,9 @@ func TestUntilMultipleConditions(t *testing.T) {
func(event watch.Event) (bool, error) { return event.Type == watch.Added, nil }, func(event watch.Event) (bool, error) { return event.Type == watch.Added, nil },
} }
ctx, _ := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...) lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...)
if err != nil { if err != nil {
t.Fatalf("expected nil error, got %#v", err) t.Fatalf("expected nil error, got %#v", err)
@ -108,7 +112,9 @@ func TestUntilMultipleConditionsFail(t *testing.T) {
func(event watch.Event) (bool, error) { return event.Type == watch.Deleted, nil }, func(event watch.Event) (bool, error) { return event.Type == watch.Deleted, nil },
} }
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...) lastEvent, err := UntilWithoutRetry(ctx, fw, conditions...)
if err != wait.ErrWaitTimeout { if err != wait.ErrWaitTimeout {
t.Fatalf("expected ErrWaitTimeout error, got %#v", err) t.Fatalf("expected ErrWaitTimeout error, got %#v", err)
@ -169,6 +175,7 @@ func TestUntilErrorCondition(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel() defer cancel()
_, err := UntilWithoutRetry(ctx, fw, conditions...) _, err := UntilWithoutRetry(ctx, fw, conditions...)
if err == nil { if err == nil {
t.Fatal("expected an error") t.Fatal("expected an error")