LinuxContainer.create() leaks the VZ VM/XPC process when vm.start() throws — no do/catch around it
Mantenedores costumam responder em até 2 dias
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 78/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- macos, swift
- Domínio
- operating-systems
Direção de pesquisa
Comece em Sources/Containerization/LinuxContainer.swift, em LinuxContainer.create(), e compare o caminho de vm.start() com a limpeza do/catch existente após a inicialização. Verifique o caminho de falha de um vm.start() que lança um erro, incluindo o desligamento do relay, a parada da VM e a transição para um estado de erro. Está concluído quando o erro lançado é propagado sem deixar o processo auxiliar do VZ ou o lease do vmnet para trás.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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().
- Linguagem predominante
- Swift
- Estrelas
- 9k
- Forks
- 412
- Merge médio
- 3d 10h
- PRs com merge (30d)
- 12
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de apple/containerization
-
[Bug]: RegistryClient ignores credentials in HTTPS_PROXY, so image pulls fail with proxyAuthenticationRequiredTalvez já em andamento @vishalhabib99 assumiu há 4 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
apple/containerization#1012 ·
Mantenedores costumam responder em até 2 dias
-
[Bug]: archive ownership changes clear set-ID permission bitsTalvez já em andamento @maksim-romanov assumiu há 101 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apple/containerization#819 · 1 comentário · 1 reação ·
Mantenedores costumam responder em até 2 dias
-
[Bug]: archive extraction strips special permission bitsTalvez já em andamento @maksim-romanov assumiu há 101 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apple/containerization#818 · 2 comentários ·
Mantenedores costumam responder em até 2 dias
-
[Bug]: TimeSyncer steps the guest clock backward every 30 s, and the first sync steps it by up to ±0.5 sTalvez já em andamento @castlemilk assumiu há 1 dia. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 46/100
apple/containerization#1019 · 1 comentário · 1 responsável ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 65/100
apple/containerization#1017 ·
Mantenedores costumam responder em até 2 dias
Todas as issues de apple/containerization
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
compiler diagnostics quality ownership SIL ownership
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 64/100
Mantenedores costumam responder em até 1 dia
-
T-Defect
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
element-hq/element-x-ios#6536 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
Switch to new string APIAbertafxios-coreexperience
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
mozilla-mobile/firefox-ios#36661 ·
Mantenedores costumam responder em até 1 dia