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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.86%. Comparing base (caf1091) to head (0a6f1b7).
⚠️ Report is 9 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (caf1091) and HEAD (0a6f1b7). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (caf1091) HEAD (0a6f1b7)
unittests 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               main   #14919       +/-   ##
=============================================
- Coverage     20.80%    3.86%   -16.95%     
=============================================
  Files          6053      494     -5559     
  Lines        548466    42888   -505578     
  Branches      73283     8141    -65142     
=============================================
- Hits         114129     1657   -112472     
+ Misses       420977    40999   -379978     
+ Partials      13360      232    -13128     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests ?

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