LinuxPod: stop the VM when setup fails after start - #847
Open
shoemoney wants to merge 1 commit into
Open
Conversation
LinuxPod.create() called vm.start() outside the do/catch that otherwise cleans up on failure. If vm.start() threw -- for example a vmnet allocation failure surfaced through network device attachment -- the VZVirtualMachine and its com.apple.Virtualization.VirtualMachine.xpc helper process were never stopped. vm is local to create(), so nothing outside could reach it to stop it afterwards. Move vm.start() inside the existing do block so its failure runs the same relayManager.stopAll() / vm.stop() / setErrored path every other setup failure already takes. This is the same fix applied to LinuxContainer.create() in apple#836, for the sibling call site in LinuxPod.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LinuxPod.create()callsvm.start()outside thedo/catchthat cleans up on failure, so athrow from
start()leaves theVZVirtualMachine— and itscom.apple.Virtualization.VirtualMachine.xpchelper process — running with nothing able to stop it.vmis local tocreate(), so once the error propagates there is no handle left to callstop()on.This is the same defect fixed for
LinuxContainer.create()in #836, at the sibling call site.Issue #804 describes the
LinuxContainercase and is still open.The change
Move
try await vm.start()inside the existingdoblock.That is the whole diff — 1 insertion, 1 deletion. No new error handling is introduced: the
catchthat already closes this block (
LinuxPod.swift:833) does exactly the right thing and is identicalin shape to the one in
LinuxContainer:So after this change a
start()failure takes the samestopAll()→stop()→setErrored()→rethrow path that every other setup failure in this function already takes.
I verified by brace depth that the
catchat line 833 is the one closing thedoopened at line 632,rather than assuming it from proximity.
Why it matters
The reproduction in #804 is a
vmnetallocation failure surfaced through network device attachment.Any
start()failure has the same effect: an orphaned VM plus a leaked XPC helper process perattempt, which accumulates across retries.
Testing
swift build --target Containerization— clean (Swift 6.4, arm64-apple-macosx,Build complete!).adds no new branches; exercising it requires inducing a real
VZVirtualMachine.start()failure,which needs host virtualization state (e.g.
vmnetexhaustion) rather than a unit-test seam.LinuxContainer: stop the VM when setup fails after start #836 landed the identical change on
LinuxContainerwithout new tests for the same reason.Notes
LinuxContainerandLinuxPodstill keep two separate copies of this create-and-start-then-clean-upsequence, which is why the fix had to be applied twice. Consolidating them is a larger refactor and
deliberately out of scope here — happy to open a follow-up issue if that is wanted.