Просмотр исходного кода

fix(rule tracing): unset trace meta data in try-after-end

We wrap the reset of the process trace meta data in the after clause of
a try-after-end expression to be sure we never get any lingering
incorrect meta data.
Kjell Winblad 1 год назад
Родитель
Сommit
3232ab5ea3
1 измененных файлов с 7 добавлено и 6 удалено
  1. 7 6
      apps/emqx_resource/src/emqx_resource_buffer_worker.erl

+ 7 - 6
apps/emqx_resource/src/emqx_resource_buffer_worker.erl

@@ -1125,12 +1125,13 @@ call_query(QM, Id, Index, Ref, Query, QueryOpts) ->
         {ok, _Group, #{status := ?status_connecting, error := unhealthy_target}} ->
             {error, {unrecoverable_error, unhealthy_target}};
         {ok, _Group, Resource} ->
-            set_rule_id_trace_meta_data(Query),
-            QueryResult = do_call_query(QM, Id, Index, Ref, Query, QueryOpts, Resource),
-            %% do_call_query does not throw an exception as the call to the
-            %% resource is wrapped in a try catch expression so we will always
-            %% unset the trace meta data
-            unset_rule_id_trace_meta_data(),
+            QueryResult =
+                try
+                    set_rule_id_trace_meta_data(Query),
+                    do_call_query(QM, Id, Index, Ref, Query, QueryOpts, Resource)
+                after
+                    unset_rule_id_trace_meta_data()
+                end,
             QueryResult;
         {error, not_found} ->
             ?RESOURCE_ERROR(not_found, "resource not found")