LinuxContainer.create() leaks the VZ VM/XPC process when vm.start() throws — no do/catch around it
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- macos, swift
調査の方向性
Sources/Containerization/LinuxContainer.swift の LinuxContainer.create() から始め、vm.start() のパスと既存の起動後の do/catch クリーンアップを比較します。エラーを throw する vm.start() の失敗パスを確認します。これには、relay のシャットダウン、VM の停止、エラー状態への遷移が含まれます。vmnet の lease や VZ helper process を残さずに、throw されたエラーが伝播されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
LinuxContainer.create() (Sources/Containerization/LinuxContainer.swift, pinned 0.35.0) calls the raw vm.start() outside the do/catch block that otherwise cleans up on failure. If vm.start() itself throws — e.g. a vmnet allocation failure surfaced through the network device attachment — the underlying VZVirtualMachine (and its com.apple.Virtualization.VirtualMachine.xpc helper process) is never stopped. Since vm is a local variable inside create(), nothing outside the function ever holds a reference to it, so there is no way for a caller to stop or clean it up after the fact either.
public func create() async throws {
try await self.state.withLock { state in
...
let vm = try await self.vmm.create(config: creationConfig)
let relayManager = UnixSocketRelayManager(vm: vm, log: self.logger)
try await vm.start() // <-- NOT inside the do/catch below; a throw here leaks `vm`
do {
try await vm.withAgent { agent in ... }
state = .created(.init(vm: vm, relayManager: relayManager, ...))
} catch {
try? await relayManager.stopAll()
try? await vm.stop()
state.setErrored(error: error)
throw error
}
}
}
Because state is never transitioned away from .initialized when vm.start() throws here, a caller's subsequent container.stop() also can't help — stop() requires .created/.started state (via state.createdState("stop") / state.startedState("stop")), both of which throw against .initialized, so stop() is a no-op in this exact failure mode.
Impact
In our case (Anglesite, a macOS app embedding this package), a transient vmnet NAT-subnet contention (a known single-consumer limitation — see apple/container's vmnet plugin) causes exactly this: vm.start() throws vmnet_return_t(rawValue: 1002), and the resulting leaked VZ process permanently holds the vmnet lease. Every subsequent boot attempt — including retries and full app relaunches — fails identically, because the orphaned com.apple.Virtualization.VirtualMachine.xpc process survives even a full quit/relaunch of the embedding app (it isn't reaped as a child of our process). The only recovery is manually finding and killing that PID.
Suggested fix
Wrap vm.start() itself in a do/catch that calls try? await vm.stop() (and relayManager.stopAll()) on failure, mirroring the existing catch that already covers the post-start setup steps — e.g.:
let vm = try await self.vmm.create(config: creationConfig)
let relayManager = UnixSocketRelayManager(vm: vm, log: self.logger)
do {
try await vm.start()
try await vm.withAgent { agent in ... }
state = .created(.init(vm: vm, relayManager: relayManager, ...))
} catch {
try? await relayManager.stopAll()
try? await vm.stop()
state.setErrored(error: error)
throw error
}
Environment
- Package version:
0.35.0(pinned via.upToNextMinor(from: "0.35.0")) - macOS: Apple Silicon, Virtualization.framework via
VZVirtualMachineManager
Happy to send a PR with the fix above if useful — wanted to check the intended failure-handling shape first, since I'm not certain whether vm.stop() is safe to call on a VM that never finished start().
- 主要言語
- Swift
- スター
- 9k
- フォーク
- 412
- 平均マージ
- 3日 10時間
- マージ済み PR(30日)
- 12
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apple/containerization のほかの issue
-
[Bug]: RegistryClient ignores credentials in HTTPS_PROXY, so image pulls fail with proxyAuthenticationRequired対応中かも @vishalhabib99 が 4 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
apple/containerization#1012 ·
メンテナーはふだん 2 日以内に返信
-
[Bug]: archive ownership changes clear set-ID permission bits対応中かも @maksim-romanov が 100 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apple/containerization#819 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
[Bug]: archive extraction strips special permission bits対応中かも @maksim-romanov が 100 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
apple/containerization#818 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
[Bug]: TimeSyncer steps the guest clock backward every 30 s, and the first sync steps it by up to ±0.5 s対応中かも @castlemilk が 1 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 46/100
apple/containerization#1019 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
apple/containerization#1017 ·
メンテナーはふだん 2 日以内に返信
apple/containerization の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
fxios-coreexperience
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
mozilla-mobile/firefox-ios#36661 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
manaflow-ai/cmux#45713 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Save the clothespinsオープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
alejandrobujan/tendedero#151 ·
メンテナーはふだん 2 日以内に返信