diff --git a/Sources/Helpers/RuntimeLinux/RuntimeLinuxHelper.swift b/Sources/Helpers/RuntimeLinux/RuntimeLinuxHelper.swift index 0529c562..554a9146 100644 --- a/Sources/Helpers/RuntimeLinux/RuntimeLinuxHelper.swift +++ b/Sources/Helpers/RuntimeLinux/RuntimeLinuxHelper.swift @@ -25,6 +25,7 @@ import Containerization import ContainerizationError import Foundation import Logging +import NIO @main struct RuntimeLinuxHelper: AsyncParsableCommand { @@ -57,6 +58,7 @@ struct RuntimeLinuxHelper: AsyncParsableCommand { log.info("stopping \(commandName)") } + let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) do { try adjustLimits() signal(SIGPIPE, SIG_IGN) @@ -68,7 +70,7 @@ struct RuntimeLinuxHelper: AsyncParsableCommand { } else { interfaceStrategy = IsolatedInterfaceStrategy() } - let server = SandboxService(root: .init(fileURLWithPath: root), interfaceStrategy: interfaceStrategy, log: log) + let server = SandboxService(root: .init(fileURLWithPath: root), interfaceStrategy: interfaceStrategy, eventLoopGroup: eventLoopGroup, log: log) let xpc = XPCServer( identifier: machServiceLabel, routes: [ @@ -89,6 +91,7 @@ struct RuntimeLinuxHelper: AsyncParsableCommand { try await xpc.listen() } catch { log.error("\(commandName) failed", metadata: ["error": "\(error)"]) + try? await eventLoopGroup.shutdownGracefully() RuntimeLinuxHelper.exit(withError: error) } } diff --git a/Sources/Services/ContainerSandboxService/SandboxService.swift b/Sources/Services/ContainerSandboxService/SandboxService.swift index b61953fc..4d23830b 100644 --- a/Sources/Services/ContainerSandboxService/SandboxService.swift +++ b/Sources/Services/ContainerSandboxService/SandboxService.swift @@ -39,7 +39,7 @@ public actor SandboxService { private let interfaceStrategy: InterfaceStrategy private var container: ContainerInfo? private let monitor: ExitMonitor - private let eventLoopGroup: MultiThreadedEventLoopGroup + private let eventLoopGroup: any EventLoopGroup private var waiters: [String: [CheckedContinuation]] = [:] private let lock: AsyncLock = AsyncLock() private let log: Logging.Logger @@ -54,12 +54,12 @@ public actor SandboxService { /// - interfaceStrategy: The strategy for producing network interface /// objects for each network to which the container attaches. /// - log: The destination for log messages. - public init(root: URL, interfaceStrategy: InterfaceStrategy, log: Logger) { + public init(root: URL, interfaceStrategy: InterfaceStrategy, eventLoopGroup: any EventLoopGroup, log: Logger) { self.root = root self.interfaceStrategy = interfaceStrategy self.log = log self.monitor = ExitMonitor(log: log) - self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) + self.eventLoopGroup = eventLoopGroup } /// Start the VM and the guest agent process for a container.