fix: ensure network cleanup runs when VMM is already dead #402
+16
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I fixed a resource leak where network interfaces (TAP devices) and Traffic Control (TC) rules were being left behind if a VMM crashed or was killed externally.
The issue was a logic flaw in how we handled the
Kill()command. Previously, the code tried to stop the VMM process first. If that failed—for example, if the process was already dead (returningESRCH)—the function would return an error immediately and skip thenetwork.Cleanup()step entirely.This was causing serious issues in crash-loop scenarios (like an OOMing unikernel). Since the cleanup never ran,
tap0_uruncdevices and TC redirect filters kept piling up in the network namespace, eventually causing network blackholes and exhausting node resources.Changes
pkg/unikontainers/unikontainers.go:
network.Cleanup("tap0_urunc")runs, even ifvmm.Stop()returns an error. If the stop fails, I log a warning but still proceed to clean up the network resources before returning.pkg/unikontainers/hypervisors/utils.go:
killProcessfunction to handlesyscall.ESRCHgracefully.nil) instead of an error. This makes the stop operation idempotent—if it's dead, my job is done.Testing
I verified this using a "zombie VMM" reproduction scenario:
Reproduction:
kill -9.urunc kill <container_id>.ip link showproved the TAP device was still there.Crash Loop:
tc filter showshowed zero orphaned rules.Impact