fix: handle `max_heap_size` = 0

Fixes https://github.com/emqx/emqx/issues/13417

Fixes https://emqx.atlassian.net/browse/EMQX-12659
This commit is contained in:
Thales Macedo Garitezi 2024-07-05 10:23:21 -03:00
parent c7f4e85760
commit 70fab51354
4 changed files with 21 additions and 2 deletions

View File

@ -289,8 +289,10 @@ do_check_oom([{Val, Max, Reason} | Rest]) ->
end. end.
tune_heap_size(#{enable := false}) -> tune_heap_size(#{enable := false}) ->
ok; ignore;
%% If the max_heap_size is set to zero, the limit is disabled. %% If the max_heap_size is set to zero, the limit is disabled.
tune_heap_size(#{max_heap_size := 0}) ->
ignore;
tune_heap_size(#{max_heap_size := MaxHeapSize}) when MaxHeapSize > 0 -> tune_heap_size(#{max_heap_size := MaxHeapSize}) when MaxHeapSize > 0 ->
MaxSize = MaxSize =
case erlang:system_info(wordsize) of case erlang:system_info(wordsize) of

View File

@ -154,6 +154,22 @@ t_check(_) ->
emqx_utils:check_oom(Policy) emqx_utils:check_oom(Policy)
). ).
t_tune_heap_size(_Config) ->
Policy = #{
max_mailbox_size => 10,
max_heap_size => 1024 * 1024 * 8,
enable => true
},
?assertEqual(ignore, emqx_utils:tune_heap_size(Policy#{enable := false})),
%% Setting it to 0 disables the check.
?assertEqual(ignore, emqx_utils:tune_heap_size(Policy#{max_heap_size := 0})),
{max_heap_size, PreviousHeapSize} = process_info(self(), max_heap_size),
try
?assertMatch(PreviousHeapSize, emqx_utils:tune_heap_size(Policy))
after
process_flag(max_heap_size, PreviousHeapSize)
end.
t_rand_seed(_) -> t_rand_seed(_) ->
?assert(is_tuple(emqx_utils:rand_seed())). ?assert(is_tuple(emqx_utils:rand_seed())).

View File

@ -0,0 +1 @@
Fixed an issue where the option `force_shutdown.max_heap_size` could not be set to 0 to disable this tuning.

View File

@ -801,7 +801,7 @@ mqtt_max_topic_levels.label:
"""Max Topic Levels""" """Max Topic Levels"""
force_shutdown_max_heap_size.desc: force_shutdown_max_heap_size.desc:
"""Total heap size""" """Total heap size. Setting this to 0 disables this limitation."""
force_shutdown_max_heap_size.label: force_shutdown_max_heap_size.label:
"""Total heap size""" """Total heap size"""