commit 79796c6: [Minor] Register more timeouts

Vsevolod Stakhov vsevolod at rspamd.com
Sat Sep 10 13:14:05 UTC 2022


Author: Vsevolod Stakhov
Date: 2022-09-10 13:47:54 +0100
URL: https://github.com/rspamd/rspamd/commit/79796c6f5f38f6ba743af8b581efd40a4e15a995

[Minor] Register more timeouts

---
 src/plugins/lua/bimi.lua              | 2 ++
 src/plugins/lua/clustering.lua        | 1 +
 src/plugins/lua/elastic.lua           | 1 +
 src/plugins/lua/history_redis.lua     | 3 ++-
 src/plugins/lua/metadata_exporter.lua | 5 +++++
 src/plugins/lua/mx_check.lua          | 1 +
 src/plugins/lua/p0f.lua               | 4 +++-
 src/plugins/lua/ratelimit.lua         | 2 ++
 src/plugins/lua/rbl.lua               | 6 ++++--
 src/plugins/lua/reputation.lua        | 3 +++
 src/plugins/lua/settings.lua          | 1 +
 src/plugins/lua/spf.lua               | 6 +++++-
 src/plugins/lua/url_redirector.lua    | 2 ++
 13 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/plugins/lua/bimi.lua b/src/plugins/lua/bimi.lua
index 405477c62..bcf5a823d 100644
--- a/src/plugins/lua/bimi.lua
+++ b/src/plugins/lua/bimi.lua
@@ -365,6 +365,8 @@ if redis_params then
     name = 'BIMI_CHECK',
     type = 'normal',
     callback = bimi_callback,
+    augmentations = {string.format("timeout=%f", settings.helper_timeout or
+        redis_params.timeout or 0.0)}
   })
   rspamd_config:register_symbol{
     name = 'BIMI_VALID',
diff --git a/src/plugins/lua/clustering.lua b/src/plugins/lua/clustering.lua
index 3e546f817..3a8a361b1 100644
--- a/src/plugins/lua/clustering.lua
+++ b/src/plugins/lua/clustering.lua
@@ -301,6 +301,7 @@ if opts['rules'] then
         type = 'idempotent',
         flags = 'empty,explicit_disable,ignore_passthrough',
         callback = callback_gen(clusterting_idempotent_cb, rule),
+        augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)}
       }
     end
   else
diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua
index 3fffd6612..5578d48ec 100644
--- a/src/plugins/lua/elastic.lua
+++ b/src/plugins/lua/elastic.lua
@@ -519,6 +519,7 @@ if redis_params and opts then
       callback = elastic_collect,
       priority = 10,
       flags = 'empty,explicit_disable,ignore_passthrough',
+      augmentations = {string.format("timeout=%f", settings.timeout)},
     })
 
     rspamd_config:add_on_load(function(cfg, ev_base,worker)
diff --git a/src/plugins/lua/history_redis.lua b/src/plugins/lua/history_redis.lua
index b8bd9466a..35bfb9242 100644
--- a/src/plugins/lua/history_redis.lua
+++ b/src/plugins/lua/history_redis.lua
@@ -290,7 +290,8 @@ if opts then
       type = 'idempotent',
       callback = history_save,
       flags = 'empty,explicit_disable,ignore_passthrough',
-      priority = 150
+      priority = 150,
+      augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)}
     })
     lua_redis.register_prefix(settings.key_prefix .. hostname, N,
         "Redis history", {
diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua
index d72454f86..c5f4ca148 100644
--- a/src/plugins/lua/metadata_exporter.lua
+++ b/src/plugins/lua/metadata_exporter.lua
@@ -484,6 +484,7 @@ if type(settings.rules) ~= 'table' then
       r.defer = settings.defer
       r.selector = settings.pusher_select.redis_pubsub
       r.formatter = settings.pusher_format.redis_pubsub
+      r.timeout = redis_params.timeout
       settings.rules[r.backend:upper()] = r
     end
   end
@@ -499,6 +500,7 @@ if type(settings.rules) ~= 'table' then
       r.defer = settings.defer
       r.selector = settings.pusher_select.http
       r.formatter = settings.pusher_format.http
+      r.timeout = settings.timeout or 0.0
       settings.rules[r.backend:upper()] = r
     end
   end
@@ -516,6 +518,7 @@ if type(settings.rules) ~= 'table' then
       r.smtp_port = settings.smtp_port
       r.email_template = settings.email_template
       r.defer = settings.defer
+      r.timeout = settings.timeout or 0.0
       r.selector = settings.pusher_select.send_mail
       r.formatter = settings.pusher_format.send_mail
       settings.rules[r.backend:upper()] = r
@@ -593,6 +596,7 @@ backend_check.redis_pubsub = function(k, rule)
     settings.rules[k] = nil
   else
     backend_check.default(k, rule)
+    rule.timeout = redis_params.timeout
   end
 end
 setmetatable(backend_check, {
@@ -650,5 +654,6 @@ for k, r in pairs(settings.rules) do
     callback = gen_exporter(r),
     priority = 10,
     flags = 'empty,explicit_disable,ignore_passthrough',
+    augmentations = {string.format("timeout=%f", r.timeout or 0.0)}
   })
 end
diff --git a/src/plugins/lua/mx_check.lua b/src/plugins/lua/mx_check.lua
index bd55cdd8f..cea636dfc 100644
--- a/src/plugins/lua/mx_check.lua
+++ b/src/plugins/lua/mx_check.lua
@@ -315,6 +315,7 @@ if opts then
     type = 'normal',
     callback = mx_check,
     flags = 'empty',
+    augmentations = {string.format("timeout=%f", settings.timeout + rspamd_config:get_dns_timeout() or 0.0)},
   })
   rspamd_config:register_symbol({
     name = settings.symbol_no_mx,
diff --git a/src/plugins/lua/p0f.lua b/src/plugins/lua/p0f.lua
index d9e91da0f..a07b1ee00 100644
--- a/src/plugins/lua/p0f.lua
+++ b/src/plugins/lua/p0f.lua
@@ -89,7 +89,9 @@ if rule then
     callback = check_p0f,
     priority = 8,
     flags = 'empty,nostat',
-    group = N
+    group = N,
+    augmentations = {string.format("timeout=%f", rule.timeout or 0.0)},
+
   })
 
   if rule.symbol then
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index 1c19d890c..2b61b606f 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -871,6 +871,7 @@ if opts then
       priority = 7,
       callback = ratelimit_cb,
       flags = 'empty,nostat',
+      augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
     }
 
     local id = rspamd_config:register_symbol(s)
@@ -914,6 +915,7 @@ if opts then
       name = 'RATELIMIT_UPDATE',
       flags = 'explicit_disable,ignore_passthrough',
       callback = ratelimit_update_cb,
+      augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
     }
   end
 end
diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua
index 890ceb232..dd69ccd67 100644
--- a/src/plugins/lua/rbl.lua
+++ b/src/plugins/lua/rbl.lua
@@ -1283,14 +1283,16 @@ rspamd_config:register_symbol{
   type = 'callback',
   callback = rbl_callback_white,
   name = 'RBL_CALLBACK_WHITE',
-  flags = 'nice,empty,no_squeeze'
+  flags = 'nice,empty,no_squeeze',
+  augmentations = {string.format("timeout=%f", rspamd_config:get_dns_timeout() or 0.0)},
 }
 
 rspamd_config:register_symbol{
   type = 'callback',
   callback = rbl_callback_fin,
   name = 'RBL_CALLBACK',
-  flags = 'empty,no_squeeze'
+  flags = 'empty,no_squeeze',
+  augmentations = {string.format("timeout=%f", rspamd_config:get_dns_timeout() or 0.0)},
 }
 
 for _, w in ipairs(white_symbols) do
diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua
index 6b7a703d6..3db6c52c7 100644
--- a/src/plugins/lua/reputation.lua
+++ b/src/plugins/lua/reputation.lua
@@ -1302,6 +1302,7 @@ local function parse_rule(name, tbl)
     name = rule.symbol,
     type = rule_type,
     callback = callback_gen(reputation_filter_cb, rule),
+    augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
   }
 
   if rule.selector.config.split_symbols then
@@ -1330,6 +1331,7 @@ local function parse_rule(name, tbl)
       type = 'postfilter',
       flags = 'nostat,explicit_disable,ignore_passthrough',
       callback = callback_gen(reputation_postfilter_cb, rule),
+      augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
     }
   end
 
@@ -1340,6 +1342,7 @@ local function parse_rule(name, tbl)
       type = 'idempotent',
       flags = 'explicit_disable,ignore_passthrough',
       callback = callback_gen(reputation_idempotent_cb, rule),
+      augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
     }
   end
 
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua
index 94e1b2327..d8f0997f1 100644
--- a/src/plugins/lua/settings.lua
+++ b/src/plugins/lua/settings.lua
@@ -1230,6 +1230,7 @@ if redis_section then
       callback = gen_redis_callback(h, id),
       priority = 10,
       flags = 'empty,nostat',
+      augmentations = {string.format("timeout=%f", redis_params.timeout or 0.0)},
     })
   end, redis_key_handlers)
 end
diff --git a/src/plugins/lua/spf.lua b/src/plugins/lua/spf.lua
index c8aeb971b..997c07bca 100644
--- a/src/plugins/lua/spf.lua
+++ b/src/plugins/lua/spf.lua
@@ -209,7 +209,11 @@ local sym_id = rspamd_config:register_symbol{
   flags = 'fine,empty',
   groups = {'policies','spf'},
   score = 0.0,
-  callback = spf_check_callback
+  callback = spf_check_callback,
+  -- We can merely estimate timeout here, as it is possible to construct an SPF record that would cause
+  -- many DNS requests. But we won't like to set the maximum value for that all the time, as
+  -- the majority of requests will typically have 1-4 subrequests
+  augmentations = {string.format("timeout=%f", rspamd_config:get_dns_timeout() * 4 or 0.0)},
 }
 
 if local_config.whitelist then
diff --git a/src/plugins/lua/url_redirector.lua b/src/plugins/lua/url_redirector.lua
index 53987ad62..bc054ec69 100644
--- a/src/plugins/lua/url_redirector.lua
+++ b/src/plugins/lua/url_redirector.lua
@@ -357,6 +357,8 @@ if opts then
         name = 'URL_REDIRECTOR_CHECK',
         type = 'callback,prefilter',
         callback = url_redirector_handler,
+        -- In fact, the real timeout is nested_limit * timeout...
+        augmentations = {string.format("timeout=%f", settings.timeout)}
       }
 
       if settings.redirector_symbol then


More information about the Commits mailing list