Skip to content

destroyVirtualMachine expunge=true reports failure for an Error-state VM that the expunge task is already removing #14966

Backlog

Description

@jmsperu

ISSUE TYPE

Bug Report

COMPONENT NAME

Management server (UserVmManagerImpl, ExpungeTask / UserVm-Scavenger)

CLOUDSTACK VERSION

4.22.1.1

CONFIGURATION

KVM, advanced zone, one management server. Defaults changed for the test only: expunge.delay=60, expunge.interval=60, expunge.workers=1 (the race exists with any values; short values only make it easy to hit).

OS / ENVIRONMENT

Ubuntu 24.04 LTS management server and two Ubuntu 24.04 KVM hosts (agent 4.22.1.1).

SUMMARY

A VM whose deployment failed is left in Error state. The background expunge task (UserVm-Scavenger, ExpungeTask) removes Error-state VMs on its own once they are older than expunge.delay. If a user or the UI calls destroyVirtualMachine with expunge=true while the expunge task is removing that VM, the API call fails, although the VM ends up removed. The caller is told the destroy failed when the result they asked for has happened.

Three different error texts come back, depending on timing:

  1. Synchronous, HTTP 431, errorcode 431 (cserrorcode 4350): Unable to find UUID for id [390] of type [VirtualMachine] (the row was already marked removed when the API resolved the uuid).
  2. Async job, errorcode 530: Unable to find VM [409]. (the destroy's VmWorkStop was queued behind the expunge task on the VM work queue and ran after the VM was gone).
  3. Async job, errorcode 530: Failed to destroy vm with specified vmId (from UserVmManagerImpl.destroyVm, UserVmManagerImpl.java:6077 in 4.22.1.1), when the work jobs succeed but the VM is expunged underneath the destroy.

Text 3 is the same text a real destroy failure gives, so a UI or script cannot tell the two apart from the response.

STEPS TO REPRODUCE

  1. Set expunge.delay=60, expunge.interval=60 (optional, makes it quick).
  2. Deploy a VM that cannot be placed, so it ends in Error state. For example a compute offering with a host tag no host carries (530 No suitable host found.), or one with more memory than any host has (533 No destination found for a deployment ...).
  3. Wait until the management log shows INFO [c.c.v.U.ExpungeTask] (UserVm-Scavenger-1...) Found N Instances to expunge.
  4. At that moment call destroyVirtualMachine id=<vm uuid> expunge=true (with two Error VMs, call it for both in parallel).
  5. Poll the job, then check the VM: listVirtualMachines id=<uuid> listall=true returns nothing, and vm_instance has removed set and state Expunging.

EXPECTED RESULTS

destroyVirtualMachine succeeds, or at least returns a clear, specific result such as "VM is already being expunged" that a client can treat as done. Destroying a VM that is being or has been expunged should be idempotent.

ACTUAL RESULTS

The call fails with one of the three texts above, while the VM is removed.

Frequency on our lab (ACS 4.22.1.1, KVM):

  • Racing the expunge task as in step 4: 6 of 6 destroys failed (3 rounds of 2 VMs), all 6 VMs removed. Errors: Unable to find VM [N]. (3) and Failed to destroy vm with specified vmId (3).
  • Not racing the expunge task: 0 of 11 failed (9 Error-state VMs destroyed straight after the failed deploy or 60 s later, plus 2 Running VMs as controls).
  • First seen during normal clean-up: 2 of 6 Error-state VMs (one sync 431, one async 530). There was no earlier destroy job or event for either VM; both were removed by the expunge task within 1 to 2 s of our call.

Log excerpt, round 1 (VM 409 and 410 in Error state, admin destroy jobs 3738 and 3739; keys removed, lines shortened):

20:56:45,338 INFO  [c.c.v.U.ExpungeTask] (UserVm-Scavenger-1) Found 2 Instances to expunge.
20:56:45,975 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] submit async job-3738 ... DestroyVMCmdByAdmin (VM 409, expunge=true)
20:56:45,978 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] submit async job-3739 ... DestroyVMCmdByAdmin (VM 410, expunge=true)
20:56:47,165 DEBUG [c.c.v.VmWorkJobDispatcher] (job-3625/job-3737) Run VM work job: com.cloud.vm.VmWorkStop for VM 409   <- expunge task's own stop
20:56:47,206 DEBUG [c.c.v.ClusteredVirtualMachineManagerImpl] (UserVm-Scavenger-1) Expunging vm VM instance {"id":409,...,"state":"Expunging"}
20:56:48,214 DEBUG [c.c.v.ClusteredVirtualMachineManagerImpl] (UserVm-Scavenger-1) Expunged VM instance {"id":409,...}
20:56:49,170 DEBUG [c.c.v.VmWorkJobDispatcher] (job-3738/job-3740) Run VM work job: com.cloud.vm.VmWorkStop for VM 409, job origin: 3738
20:56:49,171 WARN  [c.c.v.ClusteredVirtualMachineManagerImpl] (job-3738/job-3740) Unable to find VM [409].
20:56:49,171 ERROR [c.c.v.VmWorkJobHandlerProxy] (job-3738/job-3740) Invocation exception, caused by: com.cloud.utils.exception.CloudRuntimeException: Unable to find VM [409].
   -> job-3738 FAILED, 530, "Unable to find VM [409]."
20:56:51,199 DEBUG [c.c.v.ClusteredVirtualMachineManagerImpl] (UserVm-Scavenger-1) Expunging vm VM instance {"id":410,...}
20:56:52,039 DEBUG [c.c.v.ClusteredVirtualMachineManagerImpl] (UserVm-Scavenger-1) Expunged VM instance {"id":410,...}
20:56:53,231 ERROR [c.c.a.ApiAsyncJobDispatcher] (job-3739) Unexpected exception while executing DestroyVMCmdByAdmin
   com.cloud.utils.exception.CloudRuntimeException: Failed to destroy vm with specified vmId
     at com.cloud.vm.UserVmManagerImpl.destroyVm(UserVmManagerImpl.java:6077)
20:56:53,234 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl] (job-3739) Complete async job-3739, jobStatus: FAILED, resultCode: 530

After the run both VMs show state Expunging with removed set in vm_instance, and listVirtualMachines returns nothing for their ids.

SUGGESTED FIX

  • In the destroy path (UserVmManagerImpl.destroyVm and the VmWorkStop handler), if the VM is already removed or in Expunging state when the work runs, treat it as success (the requested end state is reached), or return a distinct, specific error such as VM <uuid> is already being expunged.
  • Before an API destroy queues work for a VM, check whether the expunge task holds it, or have the expunge task and the API destroy share one lock on the VM so only one of them proceeds and the other returns success.
  • At minimum, do not reuse the generic Failed to destroy vm with specified vmId for this case.

WORKAROUND

After a failed destroy of an Error-state VM, call listVirtualMachines id=: if it returns nothing, the VM is gone and the error can be ignored.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions