# HG changeset patch # User Matthew Wild # Date 1506444669 -3600 # Node ID 55a7ef2fb6283b9f88c8d96c4821a2f18314d4b8 # Parent 3092ae96c1f09981bb197e62c7f4c0d0204d3096 mod_limits: Handle fractional outstanding balance (imported from prosody 25237002aba4) diff -r 3092ae96c1f0 -r 55a7ef2fb628 mod_limits/mod_limits.lua --- 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);