Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more straightforward log for force_shutdown reason #10354

Merged
merged 2 commits into from Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/emqx/src/emqx_misc.erl
Expand Up @@ -246,7 +246,7 @@ do_check_oom([]) ->
ok;
do_check_oom([{Val, Max, Reason} | Rest]) ->
case is_integer(Max) andalso (0 < Max) andalso (Max < Val) of
true -> {shutdown, Reason};
true -> {shutdown, #{reason => Reason, value => Val, max => Max}};
false -> do_check_oom(Rest)
end.

Expand Down
18 changes: 10 additions & 8 deletions apps/emqx/src/emqx_schema.erl
Expand Up @@ -2642,20 +2642,22 @@ to_atom(Str) when is_list(Str) ->
to_atom(Bin) when is_binary(Bin) ->
binary_to_atom(Bin, utf8).

validate_heap_size(Siz) ->
validate_heap_size(Siz) when is_integer(Siz) ->
MaxSiz =
case erlang:system_info(wordsize) of
% arch_64
8 ->
(1 bsl 59) - 1;
8 -> (1 bsl 59) - 1;
% arch_32
4 ->
(1 bsl 27) - 1
4 -> (1 bsl 27) - 1
end,
case Siz > MaxSiz of
true -> error(io_lib:format("force_shutdown_policy: heap-size ~ts is too large", [Siz]));
false -> ok
end.
true ->
{error, #{reason => max_heap_size_too_large, maximum => MaxSiz}};
false ->
ok
end;
validate_heap_size(_SizStr) ->
{error, invalid_heap_size}.

validate_alarm_actions(Actions) ->
UnSupported = lists:filter(
Expand Down
5 changes: 4 additions & 1 deletion apps/emqx/test/emqx_misc_SUITE.erl
Expand Up @@ -146,7 +146,10 @@ t_check(_) ->
[self() ! {msg, I} || I <- lists:seq(1, 5)],
?assertEqual(ok, emqx_misc:check_oom(Policy)),
[self() ! {msg, I} || I <- lists:seq(1, 6)],
?assertEqual({shutdown, message_queue_too_long}, emqx_misc:check_oom(Policy)).
?assertEqual(
{shutdown, #{reason => message_queue_too_long, value => 11, max => 10}},
emqx_misc:check_oom(Policy)
).

drain() ->
drain([]).
Expand Down
2 changes: 2 additions & 0 deletions changes/ce/feat-10354.en.md
@@ -0,0 +1,2 @@
More specific error messages when configure with bad max_heap_size value.
Log current value and the max value when the `message_queue_too_long` error is thrown.