From 103b89f60ce232ec8422355d41d3a8552b7a6c02 Mon Sep 17 00:00:00 2001 From: ieQu1 <99872536+ieQu1@users.noreply.github.com> Date: Tue, 18 Jul 2023 17:37:57 +0200 Subject: [PATCH] fix(mgmt_cli): Don't crash when mria is not running --- apps/emqx_management/src/emqx_mgmt_cli.erl | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_cli.erl b/apps/emqx_management/src/emqx_mgmt_cli.erl index fcf14f17a..f778ec790 100644 --- a/apps/emqx_management/src/emqx_mgmt_cli.erl +++ b/apps/emqx_management/src/emqx_mgmt_cli.erl @@ -927,6 +927,24 @@ with_log(Fun, Msg) -> end. cluster_info() -> - #{ running_nodes => mria:running_nodes() - , stopped_nodes => mria:cluster_nodes(stopped) - }. + RunningNodes = safe_call_mria(running_nodes, [], []), + StoppedNodes = safe_call_mria(cluster_nodes, [stopped], []), + #{ + running_nodes => RunningNodes, + stopped_nodes => StoppedNodes + }. + +%% CLI starts before mria, so we should handle errors gracefully: +safe_call_mria(Fun, Args, OnFail) -> + try + apply(mria, Fun, Args) + catch + EC:Err:Stack -> + ?SLOG(warning, #{ + msg => "Call to mria failed", + call => {mria, Fun, Args}, + EC => Err, + stacktrace => Stack + }), + OnFail + end.