From 69719167a310091b581ad5aeb8900f4382d80320 Mon Sep 17 00:00:00 2001 From: Morgan Bauer Date: Thu, 26 May 2016 14:40:03 -0700 Subject: [PATCH] close channel to prevent memory leak - wait.JitterUntil goroutine is never cleaned up when used with wait.NeverStop - fixup comment --- .../volume/attachdetach/reconciler/reconciler.go | 2 +- .../attachdetach/reconciler/reconciler_test.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/pkg/controller/volume/attachdetach/reconciler/reconciler.go b/pkg/controller/volume/attachdetach/reconciler/reconciler.go index 0d7316ff1ce..020b2d84160 100644 --- a/pkg/controller/volume/attachdetach/reconciler/reconciler.go +++ b/pkg/controller/volume/attachdetach/reconciler/reconciler.go @@ -126,7 +126,7 @@ func (rc *reconciler) reconciliationLoopFunc() func() { err) } } else { - // If volume is not safe to detach (is mounted) wait a max amount of time before detaching any way. + // If volume is not safe to detach (is mounted) wait a max amount of time before detaching anyway. if timeElapsed > rc.maxWaitForUnmountDuration { glog.V(5).Infof("Attempting to start DetachVolume for volume %q from node %q. Volume is not safe to detach, but maxWaitForUnmountDuration expired.", attachedVolume.VolumeName, attachedVolume.NodeName) err := rc.attacherDetacher.DetachVolume(attachedVolume.AttachedVolume, false /* verifySafeToDetach */, rc.actualStateOfWorld) diff --git a/pkg/controller/volume/attachdetach/reconciler/reconciler_test.go b/pkg/controller/volume/attachdetach/reconciler/reconciler_test.go index a1dce7d01f1..5ba08fcdefa 100644 --- a/pkg/controller/volume/attachdetach/reconciler/reconciler_test.go +++ b/pkg/controller/volume/attachdetach/reconciler/reconciler_test.go @@ -55,7 +55,9 @@ func Test_Run_Positive_DoNothing(t *testing.T) { reconcilerLoopPeriod, maxWaitForUnmountDuration, dsw, asw, ad, nsu) // Act - go reconciler.Run(wait.NeverStop) + ch := make(chan struct{}) + go reconciler.Run(ch) + defer close(ch) // Assert waitForNewAttacherCallCount(t, 0 /* expectedCallCount */, fakePlugin) @@ -97,7 +99,9 @@ func Test_Run_Positive_OneDesiredVolumeAttach(t *testing.T) { } // Act - go reconciler.Run(wait.NeverStop) + ch := make(chan struct{}) + go reconciler.Run(ch) + defer close(ch) // Assert waitForNewAttacherCallCount(t, 1 /* expectedCallCount */, fakePlugin) @@ -140,7 +144,9 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithUnmountedVolume(t *te } // Act - go reconciler.Run(wait.NeverStop) + ch := make(chan struct{}) + go reconciler.Run(ch) + defer close(ch) // Assert waitForNewAttacherCallCount(t, 1 /* expectedCallCount */, fakePlugin) @@ -204,7 +210,9 @@ func Test_Run_Positive_OneDesiredVolumeAttachThenDetachWithMountedVolume(t *test } // Act - go reconciler.Run(wait.NeverStop) + ch := make(chan struct{}) + go reconciler.Run(ch) + defer close(ch) // Assert waitForNewAttacherCallCount(t, 1 /* expectedCallCount */, fakePlugin)