Skip to content

Commit af2edd6

Browse files
authored
Merge pull request #127 from Automattic/slot-racer2
Properly cancel VM start sequence to reduce race conditions
2 parents 41c3f30 + 3b3c8b1 commit af2edd6

File tree

7 files changed

+232
-91
lines changed

7 files changed

+232
-91
lines changed

Sources/hostmgr-helper/VM List/States/RunningVMListItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct RunningVMListItem: View {
2929

3030
func shutdown() {
3131
Task {
32-
try await slot.stopVirtualMachine()
32+
try await slot.stop()
3333
}
3434
}
3535

Sources/hostmgr-helper/VM List/VMListItem.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ struct VMListItem: View {
66
var slot: VirtualMachineSlot
77

88
var body: some View {
9-
switch slot.status {
9+
switch slot.state {
1010
case .empty: EmptyVMListItem(slot: slot)
11-
case .starting(let launchConfiguration):
11+
case .starting(let launchConfiguration, _):
1212
PendingVMListItem(
1313
launchConfiguration: launchConfiguration,
1414
slot: slot
1515
)
16-
case .running(let launchConfiguration, let ipAddress):
16+
case .running(let virtualMachine):
1717
RunningVMListItem(
18-
launchConfiguration: launchConfiguration,
19-
ipAddress: ipAddress,
18+
launchConfiguration: virtualMachine.config,
19+
ipAddress: virtualMachine.ip,
2020
slot: slot
2121
)
2222
case .stopping:

Sources/hostmgr-helper/VMHost.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ extension VMHost: HostmgrServerDelegate {
5050
Logger.helper.log("Received stop request for \(handle)")
5151

5252
if self.primaryVMSlot.isConfiguredForHandle(handle) {
53-
try await primaryVMSlot.stopVirtualMachine()
53+
try await primaryVMSlot.stop()
5454
}
5555

5656
if self.secondaryVMSlot.isConfiguredForHandle(handle) {
57-
try await secondaryVMSlot.stopVirtualMachine()
57+
try await secondaryVMSlot.stop()
5858
}
5959
}
6060

@@ -63,8 +63,8 @@ extension VMHost: HostmgrServerDelegate {
6363

6464
repeat {
6565
do {
66-
try await self.primaryVMSlot.stopVirtualMachine()
67-
try await self.secondaryVMSlot.stopVirtualMachine()
66+
try await self.primaryVMSlot.stop()
67+
try await self.secondaryVMSlot.stop()
6868
return
6969
} catch {
7070
try await Task.sleep(for: .seconds(1))

Sources/hostmgr-helper/VMWindow.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ struct VMWindowContent: View {
1010
}
1111

1212
var body: some View {
13-
switch vmSlot.status {
13+
switch vmSlot.state {
1414
case .empty: Text("VM not running")
1515
case .starting: ProgressView()
16-
case .running: VirtualMachineDisplayView(virtualMachine: vmSlot.managedVirtualMachine?.machine)
16+
case .running(let virtualMachine): VirtualMachineDisplayView(virtualMachine: virtualMachine.machine)
1717
.onAppear {
1818
NSApp.setActivationPolicy(.regular)
1919
NSApp.activate(ignoringOtherApps: true)

0 commit comments

Comments
 (0)