Skip to content

Commit

Permalink
Merge pull request #1494 from balajiv113/stop-panic
Browse files Browse the repository at this point in the history
Fix panic during stop in vz driver
  • Loading branch information
AkihiroSuda authored Apr 15, 2023
2 parents 8115a57 + b85e630 commit aedd0c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions pkg/vz/vm_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import (
"github.com/sirupsen/logrus"
)

func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine, chan error, error) {
type virtualMachineWrapper struct {
*vz.VirtualMachine
stopped bool
}

func startVM(ctx context.Context, driver *driver.BaseDriver) (*virtualMachineWrapper, chan error, error) {
server, client, err := createSockPair()
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -55,6 +60,8 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
return nil, nil, err
}

wrapper := &virtualMachineWrapper{VirtualMachine: machine, stopped: false}

errCh := make(chan error)
go func() {
//Handle errors via errCh and handle stop vm during context close
Expand Down Expand Up @@ -83,6 +90,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
logrus.Info("[VZ] - vm state change: running")
case vz.VirtualMachineStateStopped:
logrus.Info("[VZ] - vm state change: stopped")
wrapper.stopped = true
errCh <- errors.New("vz driver state stopped")
default:
logrus.Debugf("[VZ] - vm state change: %q", newState)
Expand All @@ -91,7 +99,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
}
}()

return machine, errCh, err
return wrapper, errCh, err
}

func createVM(driver *driver.BaseDriver, networkConn *os.File) (*vz.VirtualMachine, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vz/vz_driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Enabled = true
type LimaVzDriver struct {
*driver.BaseDriver

machine *vz.VirtualMachine
machine *virtualMachineWrapper
}

func New(driver *driver.BaseDriver) *LimaVzDriver {
Expand Down Expand Up @@ -138,7 +138,7 @@ func (l *LimaVzDriver) Stop(_ context.Context) error {
case <-timeout:
return errors.New("vz timeout while waiting for stop status")
case <-tick:
if l.machine.State() == vz.VirtualMachineStateStopped {
if l.machine.stopped {
return nil
}
}
Expand Down

0 comments on commit aedd0c1

Please sign in to comment.