You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ni...@apache.org on 2026/04/24 09:07:37 UTC

(apisix) branch fix/batch-processor-shutdown-infinite-loop updated: fix: address review feedback - error logging, metrics reset, test assertion

This is an automated email from the ASF dual-hosted git repository.

nic-6443 pushed a commit to branch fix/batch-processor-shutdown-infinite-loop
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/fix/batch-processor-shutdown-infinite-loop by this push:
     new 1a6ef1348 fix: address review feedback - error logging, metrics reset, test assertion
1a6ef1348 is described below

commit 1a6ef1348462470231d5eb9c79bb710ded96ea25
Author: Nic <qi...@api7.ai>
AuthorDate: Fri Apr 24 17:07:29 2026 +0800

    fix: address review feedback - error logging, metrics reset, test assertion
    
    - Log error when fallback timer creation fails in schedule_func_exec
    - Reset Prometheus gauge (set_metrics) when clearing entry_buffer during shutdown
    - Add shutdown_error_log assertion in TEST 13 to verify flush callback executes
---
 apisix/utils/batch-processor.lua | 8 +++++++-
 t/utils/batch-processor.t        | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/apisix/utils/batch-processor.lua b/apisix/utils/batch-processor.lua
index 655898b5c..077eba4dd 100644
--- a/apisix/utils/batch-processor.lua
+++ b/apisix/utils/batch-processor.lua
@@ -52,7 +52,12 @@ local function schedule_func_exec(self, delay, batch)
     local hdl, err = timer_at(delay, execute_func, self, batch)
     if not hdl then
         if err == "process exiting" then
-            timer_at(0, execute_func, self, batch)
+            local hdl2, err2 = timer_at(0, execute_func, self, batch)
+            if not hdl2 then
+                core.log.error("failed to create fallback process timer ",
+                               "while exiting: ", err2)
+                return
+            end
         else
             core.log.error("failed to create process timer: ", err)
             return
@@ -138,6 +143,7 @@ local function flush_buffer(premature, self)
         if #self.entry_buffer.entries > 0 then
             self.batch_to_process[#self.batch_to_process + 1] = self.entry_buffer
             self.entry_buffer = {entries = {}, retry_count = 0}
+            set_metrics(self, 0)
         end
         for _, batch in ipairs(self.batch_to_process) do
             execute_func(true, self, batch)
diff --git a/t/utils/batch-processor.t b/t/utils/batch-processor.t
index 4dc7c3f38..c4a7e6840 100644
--- a/t/utils/batch-processor.t
+++ b/t/utils/batch-processor.t
@@ -524,4 +524,6 @@ Batch Processor[log buffer] failed to process entries [1/2]: error after consumi
 GET /t
 --- response_body
 done
+--- shutdown_error_log
+batch-processor shutdown flush: 2 entries
 --- wait: 0.5