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:
Patrick Ohly
2025-04-17 14:15:12 +02:00
parent 047e4c8e56
commit 33f16a55ba

View File

@@ -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)