Преглед изворни кода

refactor(resource-manager-sup): do not force kill resource manager

the shutdown timeout is now set to infinity so it will never
force kill a resource manager, otherwise there will be
resource leaks
Zaiming (Stone) Shi пре 2 година
родитељ
комит
f5e5c59763

+ 1 - 1
apps/emqx_resource/src/emqx_resource_buffer_worker_sup.erl

@@ -133,7 +133,7 @@ ensure_worker_removed(ResId, Idx) ->
         ok ->
             _ = supervisor:delete_child(?SERVER, ChildId),
             %% no need to remove worker from the pool,
-            %% because the entire pool will be forece deleted later
+            %% because the entire pool will be force deleted later
             ok;
         {error, not_found} ->
             ok

+ 10 - 2
apps/emqx_resource/src/emqx_resource_manager_sup.erl

@@ -17,7 +17,7 @@
 
 -behaviour(supervisor).
 
--export([ensure_child/5]).
+-export([ensure_child/5, delete_child/1]).
 
 -export([start_link/0]).
 
@@ -27,6 +27,11 @@ ensure_child(ResId, Group, ResourceType, Config, Opts) ->
     _ = supervisor:start_child(?MODULE, [ResId, Group, ResourceType, Config, Opts]),
     ok.
 
+delete_child(Pid) ->
+    _ = supervisor:terminate_child(?MODULE, Pid),
+    _ = supervisor:delete_child(?MODULE, Pid),
+    ok.
+
 start_link() ->
     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
@@ -36,7 +41,10 @@ init([]) ->
             id => emqx_resource_manager,
             start => {emqx_resource_manager, start_link, []},
             restart => transient,
-            shutdown => brutal_kill,
+            %% never force kill a resource manager.
+            %% becasue otherwise it may lead to release leak,
+            %% resource_manager's terminate callback calls resource on_stop
+            shutdown => infinity,
             type => worker,
             modules => [emqx_resource_manager]
         }