problem
When a VM's domain is detected missing (PowerReportMissing) past the graceful period (vm.op.wait.interval), CloudStack releases its NIC (broadcast_uri/isolation_uri -> NULL, nics_count) and marks the VM Stopped. If the VM's power state later resyncs back to Running (domain restored, HA restart, etc.), the NIC is never re-reserved and nics_count is never restored.
Separately, op_networks.nics_count never counts the network's own VirtualRouter NIC, so it under-counts from network creation. Combined, a single NIC release event can drive nics_count to 0 while the network still has live NICs (including on a Running VM).
NetworkGarbageCollector trusts nics_count==0 (plus a check of CloudStack's own DB-tracked "no non-Stopped instances") without verifying against the actual nics table or hypervisor state, and proceeds to stop the VR and release the VLAN back to the dynamic allocation pool - while it may still be bridged to a live VM. In our environment, GC's cleanup step also removes the host-level bridge, making the VM unrecoverable via a normal restart.
versions
tested on 4.22 (Maybe be observed on older versions too)
The steps to reproduce the bug
- Deploy a VM on an isolated network - note the nics_count = 1 (instead of 2 for VM and VR)
- Disable HA on the VM (as HA masks the issue)
- Perform
virsh destroy <vm-name> to simulate domain loss - backup the dumpxml virsh dumpxml <vm-name> > backup.xml
- After the graceful period, CloudStack releases the NIC and decrements
nics_count to 0.
- Restore the domain via
virsh create <dumped-xml> . VM resyncs to Running, but NIC stays unreserved, counter stays 0
- Lower
network.gc.interval/network.gc.wait to accelerate the scavenger; restart management server.
virsh destroy again to bring the VM's tracked state back to Stopped
- GC fires: stops the VR, releases the VLAN, network transitions to
Allocated broadcast_uri=NULL, despite 2 live NICs still present in nics.
...
What to do about it?
- On VM power-state resync to
Running after a missing-VM event, reconcile the NIC (broadcast_uri/isolation_uri/state=Reserved) and restore nics_count.
- Harden
NetworkGarbageCollector to verify live NIC count from the nics table (WHERE network_id=? AND removed IS NULL) before tearing down a network, instead of trusting the cached counter alone
- Include the VirtualRouter's own NIC in
nics_count from network creation
problem
When a VM's domain is detected missing (
PowerReportMissing) past the graceful period (vm.op.wait.interval), CloudStack releases its NIC (broadcast_uri/isolation_uri-> NULL,nics_count) and marks the VMStopped. If the VM's power state later resyncs back toRunning(domain restored, HA restart, etc.), the NIC is never re-reserved andnics_countis never restored.Separately,
op_networks.nics_countnever counts the network's own VirtualRouter NIC, so it under-counts from network creation. Combined, a single NIC release event can drivenics_countto 0 while the network still has live NICs (including on aRunningVM).NetworkGarbageCollectortrustsnics_count==0(plus a check of CloudStack's own DB-tracked "no non-Stopped instances") without verifying against the actualnicstable or hypervisor state, and proceeds to stop the VR and release the VLAN back to the dynamic allocation pool - while it may still be bridged to a live VM. In our environment, GC's cleanup step also removes the host-level bridge, making the VM unrecoverable via a normal restart.versions
tested on 4.22 (Maybe be observed on older versions too)
The steps to reproduce the bug
virsh destroy <vm-name>to simulate domain loss - backup the dumpxmlvirsh dumpxml <vm-name> > backup.xmlnics_countto 0.virsh create <dumped-xml>. VM resyncs toRunning, but NIC stays unreserved, counter stays 0network.gc.interval/network.gc.waitto accelerate the scavenger; restart management server.virsh destroyagain to bring the VM's tracked state back toStoppedAllocatedbroadcast_uri=NULL, despite 2 live NICs still present innics....
What to do about it?
Runningafter a missing-VM event, reconcile the NIC (broadcast_uri/isolation_uri/state=Reserved) and restorenics_count.NetworkGarbageCollectorto verify live NIC count from thenicstable (WHERE network_id=? AND removed IS NULL) before tearing down a network, instead of trusting the cached counter alonenics_countfrom network creation