Skip to content

Commit 2570a99

Browse files
authored
Merge pull request #5737 from edwintorok/private/edvint/taskbugfix
CA-394882,CA-394883: Fix task server race condition, and testcase race condition
2 parents ac9279b + d78ebc0 commit 2570a99

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ocaml/xapi-idl/lib/task_server.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ functor
112112

113113
(* [next_task_id ()] returns a fresh task id *)
114114
let next_task_id =
115-
let counter = ref 0 in
116-
fun () ->
117-
let result = string_of_int !counter in
118-
incr counter ; result
115+
let counter = Atomic.make 0 in
116+
fun () -> Atomic.fetch_and_add counter 1 |> string_of_int
119117

120118
let set_cancel_trigger tasks dbg n =
121119
with_lock tasks.m (fun () -> tasks.test_cancel_trigger <- Some (dbg, n))

ocaml/xenopsd/test/test.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ let wait_for_tasks id =
9191
List.iter
9292
(function
9393
| Dynamic.Task id' ->
94-
if task_ended dbg id' then ids := StringSet.remove id' !ids
94+
(* ignore events on tasks that are not ours, they may have been deleted *)
95+
if StringSet.mem id' !ids && task_ended dbg id' then
96+
ids := StringSet.remove id' !ids
9597
| _ ->
9698
()
9799
)
@@ -100,6 +102,7 @@ let wait_for_tasks id =
100102

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

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

141145
let fail_invalid_vcpus_task id =
142146
let t = Client.TASK.stat dbg id in
147+
D.debug "%s: destroying task %s" __FUNCTION__ id ;
143148
Client.TASK.destroy dbg id ;
144149
match t.Task.state with
145150
| Task.Completed _ ->
@@ -515,6 +520,7 @@ let vm_test_parallel_start_shutdown _ =
515520
) ;
516521
let t = Unix.gettimeofday () in
517522
let tasks = List.map (fun id -> Client.VM.start dbg id false) ids in
523+
D.debug "Waiting for tasks: %s" (String.concat ", " tasks) ;
518524
wait_for_tasks tasks ;
519525
if !verbose_timings then (
520526
Printf.fprintf stderr "Cleaning up tasks\n" ;

0 commit comments

Comments
 (0)