Skip to content

Commit

Permalink
Merge pull request #10354 from zhongwencool/straightforward-log-info
Browse files Browse the repository at this point in the history
feat: more straightforward log for force_shutdown reason
  • Loading branch information
zhongwencool committed Apr 14, 2023
2 parents 0553fac + dc71a97 commit 1e07f37
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
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 @@ -2656,20 +2656,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.

0 comments on commit 1e07f37

Please sign in to comment.