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
This commit is contained in:
Zaiming (Stone) Shi 2023-05-19 18:02:38 +02:00
parent 21de0f8274
commit f5e5c59763
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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]
}