diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-03 18:40:55 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-05-03 18:40:55 +0100 |
commit | 59e81754e6d2cab79e5c3725ee6075fce5af7f6c (patch) | |
tree | 789dd4e0b8a6c920d81343d45beef7e821e35fc5 | |
parent | 36d8785fd0820ab6b5d07aad43d41da427ed9a12 (diff) | |
download | rspamd-59e81754e6d2cab79e5c3725ee6075fce5af7f6c.tar.gz rspamd-59e81754e6d2cab79e5c3725ee6075fce5af7f6c.zip |
[Fix] Fix ratelimit initialization
-rw-r--r-- | src/plugins/lua/ratelimit.lua | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index 640a2ae3d..d8bbf0dfa 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -108,7 +108,7 @@ local function parse_limits(data) else return {0, 0, 0} end - end):totable() + end):totable() end local function generate_format_string(args, is_set) @@ -129,8 +129,7 @@ local function check_limits(task, args) --- Called when value is got from server local function rate_get_cb(task, err, data) if data then - local tv = task:get_timeval() - local ntime = tv['tv_usec'] / 1000000. + tv['tv_sec'] + local ntime = rspamd_util.get_time() _.each(function(elt, limit) local bucket = elt[2] @@ -139,6 +138,8 @@ local function check_limits(task, args) local atime = elt[1] local ctime = elt[3] + if atime == 0 then return end + if atime - ctime > max_delay then rspamd_logger.infox(task, 'limit is too old: %1 seconds; ignore it', atime - ctime) @@ -182,8 +183,7 @@ local function set_limits(task, args) local function rate_set_cb(task, err, data) if data then - local tv = task:get_timeval() - local ntime = tv['tv_usec'] / 1000000. + tv['tv_sec'] + local ntime = rspamd_util.get_time() local values = {} _.each(function(elt, limit) local bucket = elt[2] @@ -193,10 +193,11 @@ local function set_limits(task, args) local ctime = elt[3] if atime - ctime > max_delay then - bucket = 1 - ctime = atime rspamd_logger.infox(task, 'limit is too old: %1 seconds; start it over', atime - ctime) + bucket = 1 + ctime = ntime + atime = ntime else if bucket > 0 then bucket = bucket - rate * (ntime - atime) + 1; @@ -208,6 +209,8 @@ local function set_limits(task, args) end end + if ctime == 0 then ctime = ntime end + local lstr = string.format('%.3f:%.3f:%.3f', ntime, bucket, ctime) table.insert(values, {limit[2], max_delay, lstr}) end, _.zip(parse_limits(data), _.iter(args))) |