aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-22 17:46:03 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-06-22 17:46:03 +0100
commit74e44aac4c67e148012f65c7812737409e98fbdd (patch)
tree83a97b0f00ef5858bf99d4b73c0729b00b695be0
parent9cf201299df667bf4811fbb2e5050b8fa06b7032 (diff)
downloadrspamd-74e44aac4c67e148012f65c7812737409e98fbdd.tar.gz
rspamd-74e44aac4c67e148012f65c7812737409e98fbdd.zip
[Fix] Some more fixes to ratelimit plugin
-rw-r--r--src/plugins/lua/ratelimit.lua27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index 7493f0ede..e73dc63ed 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -155,6 +155,14 @@ local function set_limits(task, args)
local ret, upstream
local function rate_set_cb(task, err, data)
+ if not err then
+ upstream:ok()
+ else
+ rspamd_logger.infox(task, 'got error %s when setting ratelimit record on server %s',
+ err, upstream:get_addr())
+ end
+ end
+ local function rate_get_cb(task, err, data)
if data then
local ntime = rspamd_util.get_time()
local values = {}
@@ -188,15 +196,20 @@ local function set_limits(task, args)
table.insert(values, {limit[2], max_delay, lstr})
end, fun.zip(parse_limits(data), fun.iter(args)))
- local conn = rspamd_redis.connect({
- task = task,
- host = upstream:get_addr()
- })
+ local conn
+ ret,conn,upstream = rspamd_redis_make_request(task,
+ redis_params, -- connect params
+ key, -- hash key
+ true, -- is write
+ rate_set_cb, --callback
+ 'setex', -- command
+ values[1] -- arguments
+ )
if conn then
fun.each(function(v)
conn:add_cmd('setex', v)
- end, values)
+ end, fun.drop_n(1, values))
else
rspamd_logger.infox(task, 'got error while connecting to redis: %1', addr)
upstream:fail()
@@ -211,8 +224,8 @@ local function set_limits(task, args)
ret,_,upstream = rspamd_redis_make_request(task,
redis_params, -- connect params
key, -- hash key
- true, -- is write
- rate_set_cb, --callback
+ false, -- is write
+ rate_get_cb, --callback
cmd, -- command
fun.totable(fun.map(function(l) return l[2] end, args)) -- arguments
)