Skip to content

Commit 4748bab

Browse files
engine: do not force the stop for a missing power report
`sendStop()` swallows `AgentUnavailableException` and `OperationTimedoutException` and reports success when `force` is true: } catch (final AgentUnavailableException | OperationTimedoutException e) { if (!force) { return new Pair<>(false, errorMsg); } } return new Pair<>(true, null); So a host that is unreachable or too slow to answer counts as a successful stop, and the caller goes on to release the NICs and IP addresses. A host too busy to answer is exactly the condition that produces the stale report this branch is reacting to, so that is the worst case to guess in. | report | force | on an unreachable host | |---------------------|-------|-------------------------------| | PowerOff | true | unchanged, host said it is down | | PowerReportMissing | false | back off, keep the addresses, let a later report decide | A PowerOff report is the host stating the instance is down. A missing report only means the host did not list it, which is not the same thing. Also makes `handlePowerOffReportWithNoPendingJobsOnVM()` protected so this branch can be tested. Signed-off-by: Brad House <bhouse@nexthop.ai>
1 parent 191977e commit 4748bab

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5542,7 +5542,7 @@ protected void stopUnmanagedInstanceOnReportingHost(final VMInstanceVO vm) {
55425542
vm.getInstanceName(), powerHostId, vm.getState()));
55435543
}
55445544

5545-
private void handlePowerOffReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
5545+
protected void handlePowerOffReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
55465546
switch (vm.getState()) {
55475547
case Starting:
55485548
case Stopping:
@@ -5570,9 +5570,15 @@ private void handlePowerOffReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
55705570
// on the host before giving up its resources, otherwise a still-running instance keeps its NICs and IP
55715571
// addresses while the database says they are free and they get handed to another instance.
55725572
if (PowerState.PowerOff.equals(vm.getPowerState()) || PowerState.PowerReportMissing.equals(vm.getPowerState())) {
5573+
// force is false for a missing report. sendStop() swallows AgentUnavailableException and
5574+
// OperationTimedoutException and answers success when forced, and a host too busy to answer is
5575+
// exactly the condition that produced the stale report in the first place. Backing off and letting a
5576+
// later report decide is better than freeing an address on no evidence. A PowerOff report is the
5577+
// host stating the instance is down, so that path keeps its previous behaviour.
5578+
final boolean forceStop = PowerState.PowerOff.equals(vm.getPowerState());
55735579
final VirtualMachineGuru vmGuru = getVmGuru(vm);
55745580
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
5575-
Pair<Boolean, String> result = sendStop(vmGuru, profile, true, true);
5581+
Pair<Boolean, String> result = sendStop(vmGuru, profile, forceStop, true);
55765582
if (!result.first()) {
55775583
logger.warn("Unable to stop VM {} on its host, not releasing its resources: {}", vm, result.second());
55785584
return;

0 commit comments

Comments
 (0)