From f9498508163a39c20a9c1f0853d8ac63323c3d20 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 8 Nov 2025 19:38:38 +0000 Subject: [PATCH] [Fix] Normalize batch_size once in handler to fix both code paths Move batch_size validation to handler() right after argument parsing, ensuring both process_report_date() and send_reports_by_smtp() use the normalized value. Previously the validation was only in the Redis loop, so send_reports_by_smtp() would still see invalid values (0 or negative), causing nreports <= 0 which breaks sendmail callback scheduling and prevents finish_cb from ever firing. --- lualib/rspamadm/dmarc_report.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lualib/rspamadm/dmarc_report.lua b/lualib/rspamadm/dmarc_report.lua index cddcc34ee7..1e67212373 100644 --- a/lualib/rspamadm/dmarc_report.lua +++ b/lualib/rspamadm/dmarc_report.lua @@ -609,10 +609,9 @@ local function process_report_date(opts, start_time, end_time, date) -- Process reports in batches to limit Redis connections local reports = {} - local batch_size = math.max(1, opts.batch_size or 10) - for batch_start = 1, #results, batch_size do - local batch_end = math.min(batch_start + batch_size - 1, #results) + for batch_start = 1, #results, opts.batch_size do + local batch_end = math.min(batch_start + opts.batch_size - 1, #results) lua_util.debugm(N, 'processing report batch %s to %s (of %s total)', batch_start, batch_end, #results) @@ -669,6 +668,9 @@ local function handler(args) local opts = parser:parse(args) + -- Normalize batch_size to prevent invalid values (0 or negative) breaking loops + opts.batch_size = math.max(1, opts.batch_size or 10) + pool = rspamd_mempool.create() load_config(opts) rspamd_url.init(rspamd_config:get_tld_path()) -- 2.47.3