Skip to content

Commit

Permalink
pkg/machine/apple: machine stop timeout
Browse files Browse the repository at this point in the history
The current timeout was not long enough. Systemd default is 90s so we
should wait for at least that long. Also it really doesn't make sense to
throw an error we saying we failed waiting for stop. We should hard
terminate the VM in case a graceful shutdown did not happen.

Fixes #22515

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jun 25, 2024
1 parent f62c3ec commit 7562f4c
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions pkg/machine/apple/vfkit/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"time"
Expand Down Expand Up @@ -89,33 +88,28 @@ func (vf *Helper) stateChange(newState rest.StateChange) error {
}

func (vf *Helper) Stop(force, wait bool) error {
waitDuration := time.Millisecond * 10
// TODO Add ability to wait until stopped
state := rest.Stop
if force {
if err := vf.stateChange(rest.HardStop); err != nil {
return err
}
} else {
if err := vf.stateChange(rest.Stop); err != nil {
return err
}
state = rest.HardStop
}
if err := vf.stateChange(state); err != nil {
return err
}
if !wait {
return nil
}
waitErr := fmt.Errorf("failed waiting for vm to stop")
// Backoff to wait on the machine shutdown
for i := 0; i < 11; i++ {
waitDuration := time.Millisecond * 500
// Wait up to 90s then hard force off
for i := 0; i < 180; i++ {
_, err := vf.getRawState()
if err != nil || errors.Is(err, unix.ECONNREFUSED) {
waitErr = nil
break
return nil
}
waitDuration *= 2
logrus.Debugf("backoff wait time: %s", waitDuration.String())
time.Sleep(waitDuration)
}
return waitErr
logrus.Warn("Failed to gracefully stop machine, performing hard stop")
// we waited long enough do a hard stop
return vf.stateChange(rest.HardStop)
}

// Helper describes the use of vfkit: cmdline and endpoint
Expand Down

0 comments on commit 7562f4c

Please sign in to comment.