commit 77d131d: [Fix] Try to fix a mess with settings loading by adding priorities
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Dec 30 17:28:08 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-12-30 17:23:51 +0000
URL: https://github.com/rspamd/rspamd/commit/77d131d681eb197dad596f7b46a7791c7d77e7df (HEAD -> master)
[Fix] Try to fix a mess with settings loading by adding priorities
---
lualib/lua_settings.lua | 10 +++++++---
src/plugins/lua/settings.lua | 6 ++++--
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lualib/lua_settings.lua b/lualib/lua_settings.lua
index e0fc58b9d..bf6826749 100644
--- a/lualib/lua_settings.lua
+++ b/lualib/lua_settings.lua
@@ -230,7 +230,7 @@ local function transform_settings_maybe(settings, name)
return settings
end
-local function register_settings_id(str, settings)
+local function register_settings_id(str, settings, from_postload)
local numeric_id = numeric_settings_id(str)
if known_ids[numeric_id] then
@@ -252,8 +252,10 @@ local function register_settings_id(str, settings)
}
end
- if not post_init_added then
- rspamd_config:add_post_init(function () register_settings_cb(true) end)
+ if not from_postload and not post_init_added then
+ -- Use high priority to ensure that settings are initialised early but not before all
+ -- plugins are loaded
+ rspamd_config:add_post_init(function () register_settings_cb(true) end, 150)
rspamd_config:add_config_unload(function()
if post_init_added then
known_ids = {}
@@ -300,4 +302,6 @@ exports.default_symbols = function()
return default_symbols
end
+exports.load_all_settings = register_settings_cb
+
return exports
\ No newline at end of file
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua
index 993d2a8e9..81b328b52 100644
--- a/src/plugins/lua/settings.lua
+++ b/src/plugins/lua/settings.lua
@@ -962,7 +962,8 @@ local function process_settings_table(tbl, allow_ids, mempool, is_static)
end
if elt['id'] then
- out.id = lua_settings.register_settings_id(elt.id, out)
+ -- We are here from a postload script
+ out.id = lua_settings.register_settings_id(elt.id, out, true)
lua_util.debugm(N, rspamd_config,
'added settings id to "%s": %s -> %s',
name, elt.id, out.id)
@@ -1033,6 +1034,7 @@ local function process_settings_table(tbl, allow_ids, mempool, is_static)
end
settings_initialized = true
+ lua_settings.load_all_settings(true)
rspamd_logger.infox(rspamd_config, 'loaded %1 elements of settings', nrules)
return true
@@ -1215,7 +1217,7 @@ elseif set_section and type(set_section) == "table" then
)
rspamd_config:add_post_init(function ()
process_settings_table(set_section, true, settings_map_pool, true)
- end)
+ end, 100)
end
rspamd_config:add_config_unload(function()
More information about the Commits
mailing list