Skip to content

Commit 20e5cf3

Browse files
authored
CA-423574: avoid losing stacktraces in Xenopsd (#6891)
Was trying to debug a Xenctrl exception in xenopsd, but all I was seeing was the exception, not the location it was raised. With these 2 changes I was able to see the full stacktrace. Here is how a working stacktrace looks like: ``` Raised Server_error(INTERNAL_ERROR, [ xenopsd internal error: Domain.Domain_build_pre_failed("Calling 'NUMA placement' failed: Xenctrlext.Unix_error(12, \\"Error when trying to claim memory pages\\")") 1/60 xenopsd-xc Raised at file ocaml/xenopsd/xc/domain.ml, line 1159 2/60 xenopsd-xc Called from file ocaml/xenopsd/xc/domain.ml, line 1210 3/60 xenopsd-xc Called from file ocaml/xenopsd/xc/domain.ml, line 1441 4/60 xenopsd-xc Called from file ocaml/xenopsd/xc/xenops_server_xen.ml, line 2589 5/60 xenopsd-xc Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 24 6/60 xenopsd-xc Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 7/60 xenopsd-xc Called from file ocaml/xenopsd/xc/xenops_server_xen.ml, line 2622 8/60 xenopsd-xc Called from file ocaml/xenopsd/xc/xenops_server_xen.ml, line 2653 9/60 xenopsd-xc Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 24 10/60 xenopsd-xc Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 11/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 103 12/60 xenopsd-xc Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 13/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 103 14/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 112 15/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 2575 16/60 xenopsd-xc Called from file list.ml, line 121 17/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 2568 18/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 2727 19/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 103 20/60 xenopsd-xc Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 21/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 103 22/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 112 23/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 2575 24/60 xenopsd-xc Called from file list.ml, line 121 25/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 2568 26/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 2727 27/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 103 28/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_task.ml, line 112 29/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 3428 30/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 3438 31/60 xenopsd-xc Called from file ocaml/xenopsd/lib/xenops_server.ml, line 3459 32/60 xenopsd-xc Called from file ocaml/xapi-idl/lib/task_server.ml, line 192 33/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3522 34/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 24 35/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3921 36/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3531 37/60 xapi Called from file lib/backtrace.ml, line 210 38/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3537 39/60 xapi Called from file ocaml/xapi/context.ml, line 565 40/60 xapi Called from file ocaml/xapi/context.ml, line 572 41/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3928 42/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3531 43/60 xapi Called from file ocaml/xapi/xapi_xenops.ml, line 3640 44/60 xapi Called from file ocaml/xapi/context.ml, line 565 45/60 xapi Called from file ocaml/xapi/context.ml, line 572 46/60 xapi Called from file ocaml/xapi/xapi_vm.ml, line 347 47/60 xapi Called from file ocaml/xapi/message_forwarding.ml, line 141 48/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 24 49/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 50/60 xapi Called from file ocaml/xapi/message_forwarding.ml, line 1990 51/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 24 52/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 53/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 24 54/60 xapi Called from file ocaml/libs/xapi-stdext/lib/xapi-stdext-pervasives/pervasiveext.ml, line 39 55/60 xapi Called from file ocaml/xapi/message_forwarding.ml, line 1974 56/60 xapi Called from file ocaml/xapi/rbac.ml, line 228 57/60 xapi Called from file ocaml/xapi/rbac.ml, line 238 58/60 xapi Called from file ocaml/xapi/server_helpers.ml, line 78 59/60 xapi Called from file ocaml/xapi/server_helpers.ml, line 97 60/60 xapi Called from file ocaml/libs/log/debug.ml, line 270 ```
2 parents ba43e00 + 3401127 commit 20e5cf3

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

ocaml/xenopsd/lib/xenops_task.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ let with_tracing ~name ~task f =
106106
result
107107
with exn ->
108108
let backtrace = Printexc.get_raw_backtrace () in
109+
Backtrace.is_important exn ;
109110
let error = (exn, backtrace) in
110111
let _ : (Span.t option, exn) result = Tracer.finish span ~error in
111-
raise exn
112+
Printexc.raise_with_backtrace exn backtrace
112113
)
113114
| Error e ->
114115
D.warn "Failed to start tracing: %s" (Printexc.to_string e) ;

ocaml/xenopsd/xc/xenops_server_xen.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,11 @@ module Mem = struct
658658
~default:(min, ("none", min))
659659
(reserve_memory_range dbg min max)
660660
in
661-
try f amount id with e -> delete_reservation dbg id ; raise e
661+
try f amount id
662+
with e ->
663+
let bt = Printexc.get_raw_backtrace () in
664+
delete_reservation dbg id ;
665+
Printexc.raise_with_backtrace e bt
662666

663667
(** Transfer this 'reservation' to the given domain id *)
664668
let transfer_reservation_to_domain_exn dbg domid (reservation_id, amount) =

0 commit comments

Comments
 (0)