clean up VM pipes and Swift handle on all lifecycle paths #33

Open
opened 2026-05-22 10:43:41 +00:00 by rc · 0 comments
Owner

Finding:
VM lifecycle cleanup depends heavily on process exit.

Problem:

  • Pipes are created in src/vmz.zig, but most failure paths do not close both ends.
  • The Swift engine is retained in lib/libvmz.swift and released only after successful forced stop.
  • Startup failure and early validation/create paths do not have a clear cleanup owner.

Impact:

  • This is mostly hidden while vmz exits the process from callbacks.
  • It becomes fragile if vmz.run becomes reusable, tested in-process, or embedded.
  • It also makes future lifecycle changes risky because resource cleanup is implicit.

Suggested fix:

  • Add scoped cleanup in Zig for pipe fds.
  • Add explicit VM handle destroy/release once the ABI supports it.
  • Ensure startup failure releases the Swift engine and closes fds.
  • Prefer one lifecycle owner instead of depending on callback exits.

Relevant code:

  • src/vmz.zig: pipe creation and callback-driven exits.
  • lib/libvmz.swift: retained VMBridgeEngine and release only on successful forced stop.
Finding: VM lifecycle cleanup depends heavily on process exit. Problem: - Pipes are created in `src/vmz.zig`, but most failure paths do not close both ends. - The Swift engine is retained in `lib/libvmz.swift` and released only after successful forced stop. - Startup failure and early validation/create paths do not have a clear cleanup owner. Impact: - This is mostly hidden while `vmz` exits the process from callbacks. - It becomes fragile if `vmz.run` becomes reusable, tested in-process, or embedded. - It also makes future lifecycle changes risky because resource cleanup is implicit. Suggested fix: - Add scoped cleanup in Zig for pipe fds. - Add explicit VM handle destroy/release once the ABI supports it. - Ensure startup failure releases the Swift engine and closes fds. - Prefer one lifecycle owner instead of depending on callback exits. Relevant code: - `src/vmz.zig`: pipe creation and callback-driven exits. - `lib/libvmz.swift`: retained VMBridgeEngine and release only on successful forced stop.
Sign in to join this conversation.
No labels
highprio
lowprio
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rc/vmz#33
No description provided.