From c89079261393f9a94599c9c3367ab0a8d21cc590 Mon Sep 17 00:00:00 2001 From: Gilbert Wong Date: Wed, 17 Oct 2018 17:24:05 +0800 Subject: [PATCH] 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. --- src/emqx_misc.erl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/emqx_misc.erl b/src/emqx_misc.erl index 03c42510c..852113a8c 100644 --- a/src/emqx_misc.erl +++ b/src/emqx_misc.erl @@ -63,8 +63,14 @@ proc_stats(Pid) -> -define(DISABLED, 0). init_proc_mng_policy(Zone) -> - #{max_heap_size := MaxHeapSizeInBytes} = ShutdownPolicy = - emqx_zone:get_env(Zone, force_shutdown_policy), + #{max_heap_size := MaxHeapSizeInBytes} + = 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), _ = erlang:process_flag(max_heap_size, MaxHeapSize), % zero is discarded erlang:put(force_shutdown_policy, ShutdownPolicy), @@ -106,4 +112,3 @@ is_enabled(Max) -> is_integer(Max) andalso Max > ?DISABLED. proc_info(Key) -> {Key, Value} = erlang:process_info(self(), Key), Value. -