Commit 5c6292c0 authored by Matt T. Proud's avatar Matt T. Proud

pkg/various: plug leaky time.New{Timer,Ticker}s

According to the documentation for Go package time, `time.Ticker` and `time.Timer` are uncollectable by garbage collector finalizers. They leak until otherwise stopped. This commit ensures that all remaining instances are stopped upon departure from their relative scopes.
parent ed3a29bd
...@@ -363,6 +363,7 @@ func checkEvents(t *testing.T, expectedEvents []string, ctrl *PersistentVolumeCo ...@@ -363,6 +363,7 @@ func checkEvents(t *testing.T, expectedEvents []string, ctrl *PersistentVolumeCo
// Read recorded events - wait up to 1 minute to get all the expected ones // Read recorded events - wait up to 1 minute to get all the expected ones
// (just in case some goroutines are slower with writing) // (just in case some goroutines are slower with writing)
timer := time.NewTimer(time.Minute) timer := time.NewTimer(time.Minute)
defer timer.Stop()
fakeRecorder := ctrl.eventRecorder.(*record.FakeRecorder) fakeRecorder := ctrl.eventRecorder.(*record.FakeRecorder)
gotEvents := []string{} gotEvents := []string{}
......
...@@ -2072,7 +2072,9 @@ func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHand ...@@ -2072,7 +2072,9 @@ func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHand
// that need to be sync'd. A one-second period is sufficient because the // that need to be sync'd. A one-second period is sufficient because the
// sync interval is defaulted to 10s. // sync interval is defaulted to 10s.
syncTicker := time.NewTicker(time.Second) syncTicker := time.NewTicker(time.Second)
defer syncTicker.Stop()
housekeepingTicker := time.NewTicker(housekeepingPeriod) housekeepingTicker := time.NewTicker(housekeepingPeriod)
defer housekeepingTicker.Stop()
plegCh := kl.pleg.Watch() plegCh := kl.pleg.Watch()
for { for {
if rs := kl.runtimeState.errors(); len(rs) != 0 { if rs := kl.runtimeState.errors(); len(rs) != 0 {
......
...@@ -184,6 +184,7 @@ func createHttpStreamStreams(req *http.Request, w http.ResponseWriter, opts *opt ...@@ -184,6 +184,7 @@ func createHttpStreamStreams(req *http.Request, w http.ResponseWriter, opts *opt
} }
expired := time.NewTimer(streamCreationTimeout) expired := time.NewTimer(streamCreationTimeout)
defer expired.Stop()
ctx, err := handler.waitForStreams(streamCh, opts.expectedStreams, expired.C) ctx, err := handler.waitForStreams(streamCh, opts.expectedStreams, expired.C)
if err != nil { if err != nil {
......
...@@ -484,6 +484,7 @@ func retryWithExponentialBackOff(initialDuration time.Duration, fn wait.Conditio ...@@ -484,6 +484,7 @@ func retryWithExponentialBackOff(initialDuration time.Duration, fn wait.Conditio
func waitChannelWithTimeout(ch <-chan interface{}, timeout time.Duration) error { func waitChannelWithTimeout(ch <-chan interface{}, timeout time.Duration) error {
timer := time.NewTimer(timeout) timer := time.NewTimer(timeout)
defer timer.Stop()
select { select {
case <-ch: case <-ch:
......
...@@ -146,6 +146,7 @@ func TestConnectionCloseIsImmediateThroughAProxy(t *testing.T) { ...@@ -146,6 +146,7 @@ func TestConnectionCloseIsImmediateThroughAProxy(t *testing.T) {
} }
expired := time.NewTimer(15 * time.Second) expired := time.NewTimer(15 * time.Second)
defer expired.Stop()
i := 0 i := 0
for { for {
select { select {
......
...@@ -558,6 +558,7 @@ func retryWithExponentialBackOff(initialDuration time.Duration, fn wait.Conditio ...@@ -558,6 +558,7 @@ func retryWithExponentialBackOff(initialDuration time.Duration, fn wait.Conditio
func waitChannelWithTimeout(ch <-chan interface{}, timeout time.Duration) error { func waitChannelWithTimeout(ch <-chan interface{}, timeout time.Duration) error {
timer := time.NewTimer(timeout) timer := time.NewTimer(timeout)
defer timer.Stop()
select { select {
case <-ch: case <-ch:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment