diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index c87b7729b2e..ab5f6a3f046 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -3688,7 +3688,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 4e64524fe71..3f539b25567 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -3194,6 +3194,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); }