Skip to content

server: reload the VM before recording its state when HA work fails - #14919

Open
jmsperu wants to merge 1 commit into
apache:mainfrom
jmsperu:fix-14840-ha-stale-update
Open

jmsperu wants to merge 1 commit into
apache:mainfrom
jmsperu:fix-14840-ha-stale-update

Conversation

@jmsperu

@jmsperu jmsperu commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes: #14840

When an HA attempt ends with an unchecked exception (for example a CloudRuntimeException from the start of the VM), the generic catch in HighAvailabilityManagerImpl.processWork() stores the update count and state of the VM object that was read before the attempt. The attempt has already changed the VM, so these values are stale. On the next attempt restart() compares vm.getUpdated() with work.getUpdateTime(), decides that the VM was changed by someone else and returns null, and processWork() marks the work as Done. The VM stays stopped and the remaining retries are never used.

This PR reads the VM again in that catch block before recording its update count and state, which is what restart() itself already does on its handled failure paths.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

New unit test HighAvailabilityManagerImplTest.processWorkRecordsCurrentVmStateWhenRestartThrows: restart() throws a CloudRuntimeException and the VM read after the attempt has a new update count and state. The test checks that the work stays scheduled and carries the new values.

  • With the fix: Tests run: 23, Failures: 0, Errors: 0
  • Without the fix: the new test fails with expected:<20> but was:<0>

Not tested on a live HA failure.

When an HA attempt ends with an unchecked exception, processWork() stored the
update count and state of the VM copy that was read before the attempt. The
attempt has already changed the VM, so the next attempt found a different
update count, treated the VM as changed by someone else and closed the work
as done without restarting the VM.

Read the VM again before recording its update count and state.

Fixes: apache#14840
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 20.92%. Comparing base (caf1091) to head (0a6f1b7).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...java/com/cloud/ha/HighAvailabilityManagerImpl.java 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14919      +/-   ##
============================================
+ Coverage     20.80%   20.92%   +0.12%     
- Complexity    20925    21148     +223     
============================================
  Files          6053     6057       +4     
  Lines        548466   549558    +1092     
  Branches      73283    73478     +195     
============================================
+ Hits         114129   115018     +889     
- Misses       420977   421086     +109     
- Partials      13360    13454      +94     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.37% <75.00%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@weizhouapache weizhouapache left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudRuntimeException on failing VM restart

2 participants