Skip to content

Commit cc9234c

Browse files
committed
test etcd: avoid potential data race
If the caller needs to reconfigure klog, then calling klog without proper synchronizing while stopping causes a data race. We have to ensure that the goroutine has terminated before stop returns.
1 parent 6ee2c63 commit cc9234c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

test/integration/framework/etcd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os/exec"
2727
"strconv"
2828
"strings"
29+
"sync"
2930
"syscall"
3031
"testing"
3132
"time"
@@ -146,7 +147,10 @@ func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url
146147
// try to exit etcd gracefully
147148
defer cancel()
148149
cmd.Process.Signal(syscall.SIGTERM)
150+
var wg sync.WaitGroup
151+
wg.Add(1)
149152
go func() {
153+
defer wg.Done()
150154
select {
151155
case <-ctx.Done():
152156
klog.Infof("etcd exited gracefully, context cancelled")
@@ -156,6 +160,7 @@ func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url
156160
}
157161
}()
158162
err := cmd.Wait()
163+
wg.Wait()
159164
klog.Infof("etcd exit status: %v", err)
160165
err = os.RemoveAll(etcdDataDir)
161166
if err != nil {

0 commit comments

Comments
 (0)