mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
etcd: fix 5 second delay during shutdown
The main goroutine always waited for the background goroutine, which itself only proceeded after the 5 second timeout. To tell the goroutine that it is okay to stop immediately, the main goroutine must cancel the context as soon as etcd has quit.
This commit is contained in:
@@ -153,15 +153,17 @@ func RunCustomEtcd(dataDir string, customFlags []string, output io.Writer) (url
|
||||
defer wg.Done()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
klog.Infof("etcd exited gracefully, context cancelled")
|
||||
klog.V(6).InfoS("etcd exited gracefully, context cancelled")
|
||||
case <-time.After(5 * time.Second):
|
||||
klog.Infof("etcd didn't exit in 5 seconds, killing it")
|
||||
cancel()
|
||||
}
|
||||
}()
|
||||
err := cmd.Wait()
|
||||
klog.V(2).InfoS("etcd exited", "err", err)
|
||||
// Tell goroutine that we are done.
|
||||
cancel()
|
||||
wg.Wait()
|
||||
klog.Infof("etcd exit status: %v", err)
|
||||
err = os.RemoveAll(etcdDataDir)
|
||||
if err != nil {
|
||||
klog.Warningf("error during etcd cleanup: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user