diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 6d513d50978..caf374e740c 100644 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -3696,7 +3696,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VirtualMachineGuru vmGuru = getVmGuru(vm); VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); - sendStop(vmGuru, profile, true, true); + if (!sendStop(vmGuru, profile, true, true)) { + // In case StopCommand fails, don't proceed further + return; + } try { stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOffReport, null); diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 674a4c1aa9c..03c9a23ed82 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3221,6 +3221,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir try { vmParamPair = startVirtualMachine(vmId, hostId, additonalParams, deploymentPlannerToUse); vm = vmParamPair.first(); + + // At this point VM should be in "Running" state + UserVmVO tmpVm = _vmDao.findById(vm.getId()); + if (!tmpVm.getState().equals(State.Running)) { + // Some other thread changed state of VM, possibly vmsync + throw new ConcurrentOperationException("VM " + tmpVm + " unexpectedly went to " + tmpVm.getState() + " state"); + } } finally { updateVmStateForFailedVmCreation(vm.getId(), hostId); }