Skip to content

Commit 4c728e7

Browse files
committed
vz: fix mu
Signed-off-by: Akihiro Suda <[email protected]>
1 parent ac7f7d7 commit 4c728e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pkg/vz/vm_darwin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path/filepath"
1313
"strconv"
1414
"strings"
15+
"sync"
1516
"syscall"
1617

1718
"github.com/Code-Hex/vz/v3"
@@ -29,6 +30,7 @@ import (
2930

3031
type virtualMachineWrapper struct {
3132
*vz.VirtualMachine
33+
mu sync.Mutex
3234
stopped bool
3335
}
3436

@@ -90,7 +92,9 @@ func startVM(ctx context.Context, driver *driver.BaseDriver) (*virtualMachineWra
9092
logrus.Info("[VZ] - vm state change: running")
9193
case vz.VirtualMachineStateStopped:
9294
logrus.Info("[VZ] - vm state change: stopped")
95+
wrapper.mu.Lock()
9396
wrapper.stopped = true
97+
wrapper.mu.Unlock()
9498
errCh <- errors.New("vz driver state stopped")
9599
default:
96100
logrus.Debugf("[VZ] - vm state change: %q", newState)

pkg/vz/vz_driver_darwin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ 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.stopped {
141+
l.machine.mu.Lock()
142+
stopped := l.machine.stopped
143+
l.machine.mu.Unlock()
144+
if stopped {
142145
return nil
143146
}
144147
}

0 commit comments

Comments
 (0)