Skip to content

Commit e67b9fc

Browse files
authored
CA-405971: avoid calling DB functions when in emergency mode (#6283)
This breaks emergency mode commands.
2 parents 71f64c8 + 405bcb5 commit e67b9fc

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

ocaml/xapi/server_helpers.ml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,29 @@ let do_dispatch ?session_id ?forward_op ?self:_ supports_async called_fn_name
141141
Context.of_http_req ?session_id ~internal_async_subtask ~generate_task_for
142142
~supports_async ~label ~http_req ~fd ()
143143
in
144-
let identity =
145-
try
146-
Option.map
147-
(fun session_id ->
148-
let subject =
149-
Db.Session.get_auth_user_sid ~__context ~self:session_id
150-
in
151-
Tgroup.Group.Identity.make ?user_agent:http_req.user_agent subject
152-
)
153-
session_id
154-
with _ -> None
155-
in
156-
Tgroup.of_creator (Tgroup.Group.Creator.make ?identity ()) ;
144+
( if !Xapi_globs.tgroups_enabled then
145+
let identity =
146+
try
147+
Option.map
148+
(fun session_id ->
149+
let subject =
150+
Db.Session.get_auth_user_sid ~__context ~self:session_id
151+
in
152+
Tgroup.Group.Identity.make ?user_agent:http_req.user_agent
153+
subject
154+
)
155+
( if !Xapi_globs.slave_emergency_mode then
156+
(* in emergency mode we cannot reach the coordinator,
157+
and we must not attempt to make Db calls
158+
*)
159+
None
160+
else
161+
session_id
162+
)
163+
with _ -> None
164+
in
165+
Tgroup.of_creator (Tgroup.Group.Creator.make ?identity ())
166+
) ;
157167
let sync () =
158168
let need_complete = not (Context.forwarded_task __context) in
159169
exec_with_context ~__context ~need_complete ~called_async

0 commit comments

Comments
 (0)