Skip to content

CA-394882,CA-394883: Fix task server race condition, and testcase race condition #5737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions ocaml/xapi-idl/lib/task_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ functor

(* [next_task_id ()] returns a fresh task id *)
let next_task_id =
let counter = ref 0 in
fun () ->
let result = string_of_int !counter in
incr counter ; result
let counter = Atomic.make 0 in
fun () -> Atomic.fetch_and_add counter 1 |> string_of_int

let set_cancel_trigger tasks dbg n =
with_lock tasks.m (fun () -> tasks.test_cancel_trigger <- Some (dbg, n))
Expand Down
8 changes: 7 additions & 1 deletion ocaml/xenopsd/test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ let wait_for_tasks id =
List.iter
(function
| Dynamic.Task id' ->
if task_ended dbg id' then ids := StringSet.remove id' !ids
(* ignore events on tasks that are not ours, they may have been deleted *)
if StringSet.mem id' !ids && task_ended dbg id' then
ids := StringSet.remove id' !ids
| _ ->
()
)
Expand All @@ -100,6 +102,7 @@ let wait_for_tasks id =

let success_task id =
let t = Client.TASK.stat dbg id in
D.debug "%s: destroying task %s" __FUNCTION__ id ;
Client.TASK.destroy dbg id ;
match t.Task.state with
| Task.Completed _ ->
Expand All @@ -119,6 +122,7 @@ let success_task id =

let fail_not_built_task id =
let t = Client.TASK.stat dbg id in
D.debug "%s: destroying task %s" __FUNCTION__ id ;
Client.TASK.destroy dbg id ;
match t.Task.state with
| Task.Completed _ ->
Expand All @@ -140,6 +144,7 @@ let fail_not_built_task id =

let fail_invalid_vcpus_task id =
let t = Client.TASK.stat dbg id in
D.debug "%s: destroying task %s" __FUNCTION__ id ;
Client.TASK.destroy dbg id ;
match t.Task.state with
| Task.Completed _ ->
Expand Down Expand Up @@ -515,6 +520,7 @@ let vm_test_parallel_start_shutdown _ =
) ;
let t = Unix.gettimeofday () in
let tasks = List.map (fun id -> Client.VM.start dbg id false) ids in
D.debug "Waiting for tasks: %s" (String.concat ", " tasks) ;
wait_for_tasks tasks ;
if !verbose_timings then (
Printf.fprintf stderr "Cleaning up tasks\n" ;
Expand Down
Loading