Mercurial > prosody-modules
changeset 2777:55a7ef2fb628
mod_limits: Handle fractional outstanding balance (imported from prosody 25237002aba4)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 26 Sep 2017 17:51:09 +0100 |
parents | 3092ae96c1f0 |
children | 2615facc461b |
files | mod_limits/mod_limits.lua |
diffstat | 1 files changed, 2 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_limits/mod_limits.lua Tue Sep 26 14:08:39 2017 +0100 +++ b/mod_limits/mod_limits.lua Tue Sep 26 17:51:09 2017 +0100 @@ -8,6 +8,7 @@ local filters = require "util.filters"; local throttle = require "util.throttle"; local timer = require "util.timer"; +local ceil = math.ceil; local limits_cfg = module:get_option("limits", {}); local limits_resolution = module:get_option_number("limits_resolution", 1); @@ -59,6 +60,7 @@ local ok, balance, outstanding = throttle:poll(#bytes, true); if not ok then session.log("debug", "Session over rate limit (%d) with %d (by %d), pausing", throttle.max, #bytes, outstanding); + outstanding = ceil(outstanding); session.conn:pause(); -- Read no more data from the connection until there is no outstanding data local outstanding_data = bytes:sub(-outstanding); bytes = bytes:sub(1, #bytes-outstanding);