]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Normalize batch_size once in handler to fix both code paths
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 8 Nov 2025 19:38:38 +0000 (19:38 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 8 Nov 2025 19:38:38 +0000 (19:38 +0000)
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

index cddcc34ee737f47970de412bd0af6c4f590934b9..1e6721237309cfb11b04c7578dafd8eb07f84a68 100644 (file)
@@ -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())