Procházet zdrojové kódy

Merge pull request #7419 from EMQ-YangM/fix_health_check_crash

fix(emqx_resource_instance): improve the pattern match of the call_health_check
Xinyu Liu před 3 roky
rodič
revize
0f4f6b4fb4

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

@@ -265,7 +265,7 @@ call_start(InstId, Mod, Config) ->
     ?SAFE_CALL(Mod:on_start(InstId, Config)).
 
 -spec call_health_check(instance_id(), module(), resource_state()) ->
-    {ok, resource_state()} | {error, Reason:: term(), resource_state()}.
+    {ok, resource_state()} | {error, Reason:: term()}  | {error, Reason:: term(), resource_state()}.
 call_health_check(InstId, Mod, ResourceState) ->
     ?SAFE_CALL(Mod:on_health_check(InstId, ResourceState)).
 

+ 5 - 0
apps/emqx_resource/src/emqx_resource_instance.erl

@@ -295,6 +295,11 @@ do_health_check(Group, #{id := InstId, mod := Mod, state := ResourceState0} = Da
             ets:insert(emqx_resource_instance,
                 {InstId, Group, Data#{status => connected, state => ResourceState1}}),
             ok;
+        {error, Reason} ->
+            logger:error("health check for ~p failed: ~p", [InstId, Reason]),
+            ets:insert(emqx_resource_instance,
+                {InstId, Group, Data#{status => connecting}}),
+            {error, Reason};
         {error, Reason, ResourceState1} ->
             logger:error("health check for ~p failed: ~p", [InstId, Reason]),
             ets:insert(emqx_resource_instance,