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

Merge pull request #9850 from zmstone/0127-fix-influxdb-bridge-atom-leak

0127 fix influxdb bridge atom leak
Zaiming (Stone) Shi пре 3 година
родитељ
комит
514609bcf7

+ 16 - 0
apps/emqx_bridge/src/emqx_bridge.erl

@@ -31,6 +31,7 @@
 
 -export([
     load/0,
+    unload/0,
     lookup/1,
     lookup/2,
     lookup/3,
@@ -75,6 +76,21 @@ load() ->
         maps:to_list(Bridges)
     ).
 
+unload() ->
+    unload_hook(),
+    Bridges = emqx:get_config([bridges], #{}),
+    lists:foreach(
+        fun({Type, NamedConf}) ->
+            lists:foreach(
+                fun({Name, _Conf}) ->
+                    _ = emqx_bridge_resource:stop(Type, Name)
+                end,
+                maps:to_list(NamedConf)
+            )
+        end,
+        maps:to_list(Bridges)
+    ).
+
 safe_load_bridge(Type, Name, Conf, Opts) ->
     try
         _Res = emqx_bridge_resource:create(Type, Name, Conf, Opts),

+ 1 - 1
apps/emqx_bridge/src/emqx_bridge_app.erl

@@ -39,7 +39,7 @@ start(_StartType, _StartArgs) ->
 stop(_State) ->
     emqx_conf:remove_handler(?LEAF_NODE_HDLR_PATH),
     emqx_conf:remove_handler(?TOP_LELVE_HDLR_PATH),
-    ok = emqx_bridge:unload_hook(),
+    ok = emqx_bridge:unload(),
     ok.
 
 -if(?EMQX_RELEASE_EDITION == ee).

+ 2 - 2
apps/emqx_resource/src/emqx_resource_manager.erl

@@ -309,6 +309,7 @@ init({Data, Opts}) ->
     end.
 
 terminate(_Reason, _State, Data) ->
+    _ = stop_resource(Data),
     _ = maybe_clear_alarm(Data#data.id),
     delete_cache(Data#data.id, Data#data.manager_id),
     ok.
@@ -334,8 +335,7 @@ handle_event({call, From}, start, _State, _Data) ->
 % Called when the resource received a `quit` message
 handle_event(info, quit, stopped, _Data) ->
     {stop, {shutdown, quit}};
-handle_event(info, quit, _State, Data) ->
-    _ = stop_resource(Data),
+handle_event(info, quit, _State, _Data) ->
     {stop, {shutdown, quit}};
 % Called when the resource is to be stopped
 handle_event({call, From}, stop, stopped, _Data) ->

+ 1 - 1
lib-ee/emqx_ee_connector/rebar.config

@@ -1,7 +1,7 @@
 {erl_opts, [debug_info]}.
 {deps, [
   {hstreamdb_erl, {git, "https://github.com/hstreamdb/hstreamdb_erl.git", {tag, "0.2.5"}}},
-  {influxdb, {git, "https://github.com/emqx/influxdb-client-erl", {tag, "1.1.7"}}},
+  {influxdb, {git, "https://github.com/emqx/influxdb-client-erl", {tag, "1.1.8"}}},
   {emqx, {path, "../../apps/emqx"}}
 ]}.
 

+ 1 - 1
lib-ee/emqx_ee_connector/src/emqx_ee_connector_influxdb.erl

@@ -282,7 +282,7 @@ client_config(
         {host, str(Host)},
         {port, Port},
         {pool_size, erlang:system_info(schedulers)},
-        {pool, binary_to_atom(InstId, utf8)},
+        {pool, InstId},
         {precision, atom_to_binary(maps:get(precision, Config, ms), utf8)}
     ] ++ protocol_config(Config).
 

+ 2 - 2
mix.exs

@@ -47,7 +47,7 @@ defmodule EMQXUmbrella.MixProject do
       {:lc, github: "emqx/lc", tag: "0.3.2", override: true},
       {:redbug, "2.0.8"},
       {:typerefl, github: "ieQu1/typerefl", tag: "0.9.1", override: true},
-      {:ehttpc, github: "emqx/ehttpc", tag: "0.4.4", override: true},
+      {:ehttpc, github: "emqx/ehttpc", tag: "0.4.5", override: true},
       {:gproc, github: "uwiger/gproc", tag: "0.8.0", override: true},
       {:jiffy, github: "emqx/jiffy", tag: "1.0.5", override: true},
       {:cowboy, github: "emqx/cowboy", tag: "2.9.0", override: true},
@@ -57,7 +57,7 @@ defmodule EMQXUmbrella.MixProject do
       {:gen_rpc, github: "emqx/gen_rpc", tag: "2.8.1", override: true},
       {:grpc, github: "emqx/grpc-erl", tag: "0.6.7", override: true},
       {:minirest, github: "emqx/minirest", tag: "1.3.7", override: true},
-      {:ecpool, github: "emqx/ecpool", tag: "0.5.2", override: true},
+      {:ecpool, github: "emqx/ecpool", tag: "0.5.3", override: true},
       {:replayq, github: "emqx/replayq", tag: "0.3.6", override: true},
       {:pbkdf2, github: "emqx/erlang-pbkdf2", tag: "2.0.4", override: true},
       {:emqtt, github: "emqx/emqtt", tag: "1.7.0-rc.2", override: true},

+ 2 - 2
rebar.config

@@ -49,7 +49,7 @@
     , {gpb, "4.19.5"} %% gpb only used to build, but not for release, pin it here to avoid fetching a wrong version due to rebar plugins scattered in all the deps
     , {typerefl, {git, "https://github.com/ieQu1/typerefl", {tag, "0.9.1"}}}
     , {gun, {git, "https://github.com/emqx/gun", {tag, "1.3.9"}}}
-    , {ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.4.4"}}}
+    , {ehttpc, {git, "https://github.com/emqx/ehttpc", {tag, "0.4.5"}}}
     , {gproc, {git, "https://github.com/uwiger/gproc", {tag, "0.8.0"}}}
     , {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.5"}}}
     , {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.0"}}}
@@ -59,7 +59,7 @@
     , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.1"}}}
     , {grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.7"}}}
     , {minirest, {git, "https://github.com/emqx/minirest", {tag, "1.3.7"}}}
-    , {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.2"}}}
+    , {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.3"}}}
     , {replayq, {git, "https://github.com/emqx/replayq.git", {tag, "0.3.6"}}}
     , {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}
     , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.7.0-rc.2"}}}