From d3adc9b1f1e78e536ac15db49904a8fe5cff792d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Mon, 6 Dec 2021 10:02:13 +0800 Subject: [PATCH] fix(batch-processor): we didn't free stale object actually (#5700) --- apisix/plugins/http-logger.lua | 3 ++- apisix/plugins/kafka-logger.lua | 3 +-- apisix/plugins/sls-logger.lua | 3 ++- apisix/plugins/syslog.lua | 4 ++-- apisix/plugins/tcp-logger.lua | 4 ++-- apisix/plugins/udp-logger.lua | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apisix/plugins/http-logger.lua b/apisix/plugins/http-logger.lua index 3d2e7f16a4bf..60e41dfa3ecc 100644 --- a/apisix/plugins/http-logger.lua +++ b/apisix/plugins/http-logger.lua @@ -25,6 +25,7 @@ local plugin = require("apisix.plugin") local ngx = ngx local tostring = tostring local ipairs = ipairs +local pairs = pairs local timer_at = ngx.timer.at local plugin_name = "http-logger" @@ -150,7 +151,7 @@ local function remove_stale_objects(premature) return end - for key, batch in ipairs(buffers) do + for key, batch in pairs(buffers) do if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then core.log.warn("removing batch processor stale object, conf: ", core.json.delay_encode(key)) diff --git a/apisix/plugins/kafka-logger.lua b/apisix/plugins/kafka-logger.lua index b680bd4c36f6..45b1822f7c66 100644 --- a/apisix/plugins/kafka-logger.lua +++ b/apisix/plugins/kafka-logger.lua @@ -23,7 +23,6 @@ local plugin = require("apisix.plugin") local math = math local pairs = pairs local type = type -local ipairs = ipairs local plugin_name = "kafka-logger" local stale_timer_running = false local timer_at = ngx.timer.at @@ -138,7 +137,7 @@ local function remove_stale_objects(premature) return end - for key, batch in ipairs(buffers) do + for key, batch in pairs(buffers) do if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then core.log.warn("removing batch processor stale object, conf: ", core.json.delay_encode(key)) diff --git a/apisix/plugins/sls-logger.lua b/apisix/plugins/sls-logger.lua index daeaebb7dff0..797b85fd8894 100644 --- a/apisix/plugins/sls-logger.lua +++ b/apisix/plugins/sls-logger.lua @@ -26,6 +26,7 @@ local tcp = ngx.socket.tcp local buffers = {} local tostring = tostring local ipairs = ipairs +local pairs = pairs local table = table local schema = { type = "object", @@ -116,7 +117,7 @@ local function remove_stale_objects(premature) return end - for key, batch in ipairs(buffers) do + for key, batch in pairs(buffers) do if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then core.log.warn("removing batch processor stale object, route id:", tostring(key)) buffers[key] = nil diff --git a/apisix/plugins/syslog.lua b/apisix/plugins/syslog.lua index a3ec82292fb3..3eed59ff433f 100644 --- a/apisix/plugins/syslog.lua +++ b/apisix/plugins/syslog.lua @@ -22,7 +22,7 @@ local logger_socket = require("resty.logger.socket") local plugin_name = "syslog" local ngx = ngx local buffers = {} -local ipairs = ipairs +local pairs = pairs local stale_timer_running = false; local timer_at = ngx.timer.at @@ -121,7 +121,7 @@ local function remove_stale_objects(premature) return end - for key, batch in ipairs(buffers) do + for key, batch in pairs(buffers) do if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then core.log.warn("removing batch processor stale object, conf: ", core.json.delay_encode(key)) diff --git a/apisix/plugins/tcp-logger.lua b/apisix/plugins/tcp-logger.lua index dc4cb2121bae..8d678b33ca1b 100644 --- a/apisix/plugins/tcp-logger.lua +++ b/apisix/plugins/tcp-logger.lua @@ -22,7 +22,7 @@ local tostring = tostring local buffers = {} local ngx = ngx local tcp = ngx.socket.tcp -local ipairs = ipairs +local pairs = pairs local stale_timer_running = false local timer_at = ngx.timer.at @@ -106,7 +106,7 @@ local function remove_stale_objects(premature) return end - for key, batch in ipairs(buffers) do + for key, batch in pairs(buffers) do if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then core.log.warn("removing batch processor stale object, conf: ", core.json.delay_encode(key)) diff --git a/apisix/plugins/udp-logger.lua b/apisix/plugins/udp-logger.lua index 06f903e6d607..97e6552cfd65 100644 --- a/apisix/plugins/udp-logger.lua +++ b/apisix/plugins/udp-logger.lua @@ -22,7 +22,7 @@ local tostring = tostring local buffers = {} local ngx = ngx local udp = ngx.socket.udp -local ipairs = ipairs +local pairs = pairs local stale_timer_running = false; local timer_at = ngx.timer.at @@ -90,7 +90,7 @@ local function remove_stale_objects(premature) return end - for key, batch in ipairs(buffers) do + for key, batch in pairs(buffers) do if #batch.entry_buffer.entries == 0 and #batch.batch_to_process == 0 then core.log.warn("removing batch processor stale object, conf: ", core.json.delay_encode(key))