Skip to content

Commit

Permalink
xapi_main: enable backtraces earlier to get backtraces from early sta…
Browse files Browse the repository at this point in the history
…rtup failures

If 'server_init' raised an exception previously we wouldn't be able to log the full stacktrace.
Enable backtraces earlier to ensure that we can.

We need to use Debug.with_thread_associated instead of just Backtrace.with_backtraces, because if the thread is not registered,
then xapi-backtrace won't print the backtrace even if it has one.

A startup failure now looks like this in the logs:
```
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] Xapi.watchdog failed with exception Unix.Unix_error(Unix.EMFILE, "dup", "")
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] Raised Unix.Unix_error(Unix.EMFILE, "dup", "")
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 1/7 xapi Raised at file ocaml/libs/xapi-stdext/lib/xapi-stdext-unix/unixext.ml, line 873
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 2/7 xapi Called from file ocaml/xapi/xapi.ml, line 936
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 3/7 xapi Called from file ocaml/xapi/xapi.ml, line 946
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 4/7 xapi Called from file ocaml/xapi/xapi.ml, line 1535
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 5/7 xapi Called from file ocaml/xapi/xapi.ml, line 1541
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 6/7 xapi Called from file ocaml/xapi/xapi.ml, line 1548
Jun 19 04:58:41 lcy2-dt72 xapi: [error||0 ||backtrace] 7/7 xapi Called from file ocaml/libs/log/debug.ml, line 250
```

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
  • Loading branch information
edwintorok committed Jun 19, 2024
1 parent 3500e5a commit 12f4b05
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ocaml/xapi/xapi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1541,12 +1541,11 @@ let delay_on_eintr f =
Backtrace.is_important e ; raise e

let watchdog f =
if !Xapi_globs.nowatchdog then (
try
ignore (Unix.sigprocmask Unix.SIG_UNBLOCK [Sys.sigint]) ;
delay_on_eintr f ;
exit 127
with e ->
Debug.log_backtrace e (Backtrace.get e) ;
exit 2
)
let run () =
ignore (Unix.sigprocmask Unix.SIG_UNBLOCK [Sys.sigint]) ;
delay_on_eintr f ;
exit 127
in
if !Xapi_globs.nowatchdog then
(* backtrace already logged by the Debug module, so ignore the exception here *)
try Debug.with_thread_associated __FUNCTION__ run () with _ -> exit 2

0 comments on commit 12f4b05

Please sign in to comment.