Skip to content

Commit 9a2e0fc

Browse files
committed
fix goroutine that lives too long
1 parent db9f1e9 commit 9a2e0fc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"reflect"
2323
goruntime "runtime"
2424
"strconv"
25+
"sync"
2526
"testing"
2627
"time"
2728

@@ -941,8 +942,12 @@ func TestWatchBookmarksWithCorrectResourceVersion(t *testing.T) {
941942
defer watcher.Stop()
942943

943944
done := make(chan struct{})
944-
defer close(done)
945+
var wg sync.WaitGroup
946+
wg.Add(1)
947+
defer wg.Wait() // We must wait for the waitgroup to exit before we terminate the cache or the server in prior defers
948+
defer close(done) // call close first, so the goroutine knows to exit
945949
go func() {
950+
defer wg.Done()
946951
for i := 0; i < 100; i++ {
947952
select {
948953
case <-done:

0 commit comments

Comments
 (0)