Merge pull request #61976 from atlassian/ticker-with-stop

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Stop() for Ticker to enable leak-free code

**What this PR does / why we need it**:
I wanted to use the clock package but the `Ticker` without a `Stop()` method is a deal breaker for me.

**Release note**:
```release-note
NONE
```
/kind enhancement
/sig api-machinery

Kubernetes-commit: d42df4561a6c754120e9b46b37c032a57ca92a9a
This commit is contained in:
Kubernetes Publisher 2018-05-09 19:06:56 -07:00
commit 638bb430f4
3 changed files with 84 additions and 86 deletions

158
Godeps/Godeps.json generated
View File

@ -252,319 +252,319 @@
},
{
"ImportPath": "k8s.io/api/admissionregistration/v1alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/admissionregistration/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/apps/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/apps/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/apps/v1beta2",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/authentication/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/authentication/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/authorization/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/authorization/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/autoscaling/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/autoscaling/v2beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/batch/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/batch/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/batch/v2alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/certificates/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/core/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/events/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/extensions/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/imagepolicy/v1alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/networking/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/policy/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/rbac/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/rbac/v1alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/rbac/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/scheduling/v1alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/settings/v1alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/storage/v1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/storage/v1alpha1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/api/storage/v1beta1",
"Rev": "8ab7c6a2fbd1724a52514855629cec31a8f86929"
"Rev": "53d615ae3f440f957cb9989d989d597f047262d9"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/fuzzer",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/testing/roundtrip",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/fuzzer",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/internalversion",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/cache",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/clock",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream/spdy",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/remotecommand",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/netutil",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "dd7876c087d16d10b82489a4dac9e3f4427176ca"
"Rev": "13b73596e4b63e03203e86f6d9c7bcc1b937c62f"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",

View File

@ -45,7 +45,7 @@ func newDelayingQueue(clock clock.Clock, name string) DelayingInterface {
ret := &delayingType{
Interface: NewNamed(name),
clock: clock,
heartbeat: clock.Tick(maxWait),
heartbeat: clock.NewTicker(maxWait),
stopCh: make(chan struct{}),
waitingForAddCh: make(chan *waitFor, 1000),
metrics: newRetryMetrics(name),
@ -67,10 +67,7 @@ type delayingType struct {
stopCh chan struct{}
// heartbeat ensures we wait no more than maxWait before firing
//
// TODO: replace with Ticker (and add to clock) so this can be cleaned up.
// clock.Tick will leak.
heartbeat <-chan time.Time
heartbeat clock.Ticker
// waitingForAddCh is a buffered channel that feeds waitingForAdd
waitingForAddCh chan *waitFor
@ -138,6 +135,7 @@ func (pq waitForPriorityQueue) Peek() interface{} {
func (q *delayingType) ShutDown() {
q.Interface.ShutDown()
close(q.stopCh)
q.heartbeat.Stop()
}
// AddAfter adds the given item to the work queue after the given delay
@ -209,7 +207,7 @@ func (q *delayingType) waitingLoop() {
case <-q.stopCh:
return
case <-q.heartbeat:
case <-q.heartbeat.C():
// continue the loop, which will add ready items
case <-nextReadyAt:

View File

@ -30,7 +30,7 @@ func TestRateLimitingQueue(t *testing.T) {
delayingQueue := &delayingType{
Interface: New(),
clock: fakeClock,
heartbeat: fakeClock.Tick(maxWait),
heartbeat: fakeClock.NewTicker(maxWait),
stopCh: make(chan struct{}),
waitingForAddCh: make(chan *waitFor, 1000),
metrics: newRetryMetrics(""),