Skip to content

Commit aedd0c1

Browse files
authored
Merge pull request #1494 from balajiv113/stop-panic
Fix panic during stop in vz driver
2 parents 8115a57 + b85e630 commit aedd0c1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pkg/vz/vm_darwin.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import (
2727
"github.com/sirupsen/logrus"
2828
)
2929

30-
func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine, chan error, error) {
30+
type virtualMachineWrapper struct {
31+
*vz.VirtualMachine
32+
stopped bool
33+
}
34+
35+
func startVM(ctx context.Context, driver *driver.BaseDriver) (*virtualMachineWrapper, chan error, error) {
3136
server, client, err := createSockPair()
3237
if err != nil {
3338
return nil, nil, err
@@ -55,6 +60,8 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
5560
return nil, nil, err
5661
}
5762

63+
wrapper := &virtualMachineWrapper{VirtualMachine: machine, stopped: false}
64+
5865
errCh := make(chan error)
5966
go func() {
6067
//Handle errors via errCh and handle stop vm during context close
@@ -83,6 +90,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
8390
logrus.Info("[VZ] - vm state change: running")
8491
case vz.VirtualMachineStateStopped:
8592
logrus.Info("[VZ] - vm state change: stopped")
93+
wrapper.stopped = true
8694
errCh <- errors.New("vz driver state stopped")
8795
default:
8896
logrus.Debugf("[VZ] - vm state change: %q", newState)
@@ -91,7 +99,7 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*vz.VirtualMachine
9199
}
92100
}()
93101

94-
return machine, errCh, err
102+
return wrapper, errCh, err
95103
}
96104

97105
func createVM(driver *driver.BaseDriver, networkConn *os.File) (*vz.VirtualMachine, error) {

pkg/vz/vz_driver_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Enabled = true
2626
type LimaVzDriver struct {
2727
*driver.BaseDriver
2828

29-
machine *vz.VirtualMachine
29+
machine *virtualMachineWrapper
3030
}
3131

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

0 commit comments

Comments
 (0)