Skip to content

Commit 2434885

Browse files
author
Matthias Goergens
committed
Worked around a race condition in vm-uninstall.
VM.hard_shutdown now checks for an exception that signals an invalid power state, i.e. if the VM is already halted. See the Jira-ticket CA-44120 for more details. Signed-off-by: Matthias Goergens <[email protected]>
1 parent 81affe7 commit 2434885

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

ocaml/xapi/xapi_vm.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,21 @@ let hard_reboot ~__context ~vm =
623623

624624
(** VM.hard_shutdown entrypoint *)
625625
let hard_shutdown ~__context ~vm =
626-
let action = Db.VM.get_actions_after_shutdown ~__context ~self:vm in
627-
record_shutdown_details ~__context ~vm Xal.Halted "external" action;
628-
let args = { TwoPhase.__context=__context; vm=vm; api_call_name="VM.hard_shutdown"; clean=false } in
629-
retry_on_conflict args (of_action action)
626+
try
627+
let action = Db.VM.get_actions_after_shutdown ~__context ~self:vm in
628+
record_shutdown_details ~__context ~vm Xal.Halted "external" action;
629+
let args = { TwoPhase.__context=__context; vm=vm; api_call_name="VM.hard_shutdown"; clean=false } in
630+
retry_on_conflict args (of_action action)
631+
with
632+
| Api_errors.Server_error(code, _) as e
633+
when code = Api_errors.vm_bad_power_state ->
634+
(* ToDo: How do you test directly if the VM is already shut-down?
635+
I hope we are not masking bugs here.
636+
*)
637+
debug ("hard_shutdown: VM_BAD_POWER_STATE raised, and caught. Probably it was already halted.")
638+
| e ->
639+
(debug ("hard_shutdown: caught any exception besides VM_BAD_POWER_STATE, re-raising.");
640+
raise e)
630641

631642
(** VM.clean_reboot entrypoint *)
632643
let clean_reboot ~__context ~vm =

0 commit comments

Comments
 (0)