mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 18:00:08 +00:00
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.
This commit is contained in:
parent
6ee2c63135
commit
cc9234cffd
@ -26,6 +26,7 @@ import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
@ -146,7 +147,10 @@ func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url
|
||||
// try to exit etcd gracefully
|
||||
defer cancel()
|
||||
cmd.Process.Signal(syscall.SIGTERM)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
klog.Infof("etcd exited gracefully, context cancelled")
|
||||
@ -156,6 +160,7 @@ func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url
|
||||
}
|
||||
}()
|
||||
err := cmd.Wait()
|
||||
wg.Wait()
|
||||
klog.Infof("etcd exit status: %v", err)
|
||||
err = os.RemoveAll(etcdDataDir)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user