From 9aa552593b4882055d7b77bbb04911442bbd583d Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Fri, 5 Sep 2025 11:14:52 -0700 Subject: [PATCH] LinuxContainer: Try and stop vm on start failure (#281) If start fails today the vm stays running. --- Sources/Containerization/LinuxContainer.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Containerization/LinuxContainer.swift b/Sources/Containerization/LinuxContainer.swift index 2728a6ed..a2e5f612 100644 --- a/Sources/Containerization/LinuxContainer.swift +++ b/Sources/Containerization/LinuxContainer.swift @@ -481,8 +481,9 @@ extension LinuxContainer { config.interfaces } - /// Create the underlying container's virtual machine - /// and set up the runtime environment. + /// Create and start the underlying container's virtual machine + /// and set up the runtime environment. The container's init process + /// is NOT running afterwards. public func create() async throws { try self.state.withLock { try $0.setCreating() } @@ -538,7 +539,7 @@ extension LinuxContainer { } } - /// Start the container container's initial process. + /// Start the container's initial process. public func start() async throws { let vm = try self.state.withLock { try $0.setStarting() } @@ -569,6 +570,7 @@ extension LinuxContainer { try self.state.withLock { try $0.setStarted(process: process) } } catch { try? await agent.close() + try? await vm.stop() self.state.withLock { $0.errored(error: error) } throw error }