Merge pull request #107815 from aojea/revert_ipvs_race

Fix race on unit test "kube-proxy ipvs: fix to prevent concurrent map read and map w…
This commit is contained in:
Kubernetes Prow Robot 2022-01-27 03:02:25 -08:00 committed by GitHub
commit b95e192ba4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -80,6 +80,14 @@ func (q *graceTerminateRSList) remove(rs *listItem) bool {
return false
}
// return the size of the list
func (q *graceTerminateRSList) len() int {
q.lock.Lock()
defer q.lock.Unlock()
return len(q.list)
}
func (q *graceTerminateRSList) flushList(handler func(rsToDelete *listItem) (bool, error)) bool {
q.lock.Lock()
defer q.lock.Unlock()

View File

@ -18,10 +18,11 @@ package ipvs
import (
"fmt"
netutils "k8s.io/utils/net"
"reflect"
"testing"
netutils "k8s.io/utils/net"
utilipvs "k8s.io/kubernetes/pkg/util/ipvs"
utilipvstest "k8s.io/kubernetes/pkg/util/ipvs/testing"
)
@ -403,18 +404,28 @@ func Test_GracefulDeleteRS(t *testing.T) {
}
func Test_RaceTerminateRSList(t *testing.T) {
ipvs := &utilipvstest.FakeIPVS{}
ipvs := utilipvstest.NewFake()
gracefulTerminationManager := NewGracefulTerminationManager(ipvs)
// run in parallel to cause the race
go func() {
for i := 1; i <= 10; i++ {
for j := 1; i <= 100; j++ {
gracefulTerminationManager.rsList.add(makeListItem(i, j))
for j := 1; j <= 100; j++ {
item := makeListItem(i, j)
gracefulTerminationManager.rsList.add(item)
}
}
}()
if !gracefulTerminationManager.rsList.flushList(gracefulTerminationManager.deleteRsFunc) {
// wait until the list has some elements
for gracefulTerminationManager.rsList.len() < 20 {
}
// fake the handler to avoid the check against the IPVS virtual servers
fakeHandler := func(rsToDelete *listItem) (bool, error) {
return true, nil
}
if !gracefulTerminationManager.rsList.flushList(fakeHandler) {
t.Error("failed to flush entries")
}
}