Skip to content

Fix duplicate RUNNING_VM helper record creation on repeated VM.START events#12606

Open
SURYAS1306 wants to merge 1 commit intoapache:mainfrom
SURYAS1306:fix-duplicate-running-vm-usage
Open

Fix duplicate RUNNING_VM helper record creation on repeated VM.START events#12606
SURYAS1306 wants to merge 1 commit intoapache:mainfrom
SURYAS1306:fix-duplicate-running-vm-usage

Conversation

@SURYAS1306
Copy link

@SURYAS1306 SURYAS1306 commented Feb 6, 2026

Description

Repeated VM.START events for the same VM could result in duplicate
RUNNING_VM helper usage records being created in the usage database.

This PR adds a defensive check in UsageManagerImpl#createVMHelperEvent
to detect an existing active RUNNING_VM usage record (same VM instance,
endDate = NULL) and skip helper record creation when a duplicate START
event is received.

A regression test has been added to ensure that duplicate RUNNING_VM
helper records are not created when repeated VM.START events are
processed.

Fixes: #12590

Expected behavior

Only one active RUNNING_VM usage helper record should exist per VM at
any given time.

Actual behavior

Multiple RUNNING_VM helper records could be created for the same VM
when duplicate VM.START events were processed.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Test (unit or integration test code)

Bug Severity

  • Minor

How Has This Been Tested?

  • Added a unit test in UsageManagerImplTest to verify that duplicate
    RUNNING_VM helper records are not created when repeated VM.START
    events are handled.
  • Built and tested the cloud-usage module successfully using Maven.

How did you try to break this feature and the system with this change?

  • Simulated repeated VM.START events for the same VM instance to ensure
    that helper record creation is skipped when an active RUNNING_VM
    record already exists.

@boring-cyborg
Copy link

boring-cyborg bot commented Feb 6, 2026

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate event in the usage_event causes it to never get processed

1 participant