Fix the init_proc_mng_policy bug

Prior to this change, when the plugin like emqx_sn_gateway which has
no zone run the init_proc_mng_policy function, it would trigger error
and application crash.

This change add a case to avoid crash.
This commit is contained in:
Gilbert Wong 2018-10-17 17:24:05 +08:00
parent d36a34fb59
commit c890792613
1 changed files with 8 additions and 3 deletions

View File

@ -63,8 +63,14 @@ proc_stats(Pid) ->
-define(DISABLED, 0). -define(DISABLED, 0).
init_proc_mng_policy(Zone) -> init_proc_mng_policy(Zone) ->
#{max_heap_size := MaxHeapSizeInBytes} = ShutdownPolicy = #{max_heap_size := MaxHeapSizeInBytes}
emqx_zone:get_env(Zone, force_shutdown_policy), = ShutdownPolicy
= case Zone of
undefined ->
#{max_heap_size => 0};
_ ->
emqx_zone:get_env(Zone, force_shutdown_policy)
end,
MaxHeapSize = MaxHeapSizeInBytes div erlang:system_info(wordsize), MaxHeapSize = MaxHeapSizeInBytes div erlang:system_info(wordsize),
_ = erlang:process_flag(max_heap_size, MaxHeapSize), % zero is discarded _ = erlang:process_flag(max_heap_size, MaxHeapSize), % zero is discarded
erlang:put(force_shutdown_policy, ShutdownPolicy), erlang:put(force_shutdown_policy, ShutdownPolicy),
@ -106,4 +112,3 @@ is_enabled(Max) -> is_integer(Max) andalso Max > ?DISABLED.
proc_info(Key) -> proc_info(Key) ->
{Key, Value} = erlang:process_info(self(), Key), {Key, Value} = erlang:process_info(self(), Key),
Value. Value.