# HG changeset patch # User Matthew Wild # Date 1506444513 -3600 # Node ID 25237002aba4095b174cd0b99ab6765a8e864ea4 # Parent 42fad8465537956718a1152ea0ca6b369ebf4f33 mod_limits: Handle fractional outstanding balance values (caused by e3f7b6fa46ba) Fractional values were passed to string.sub() when doing buffer manipulations, and caused random bytes to be skipped in the stream. diff -r 42fad8465537 -r 25237002aba4 plugins/mod_limits.lua --- a/plugins/mod_limits.lua Mon Sep 25 23:12:47 2017 +0100 +++ b/plugins/mod_limits.lua Tue Sep 26 17:48:33 2017 +0100 @@ -4,6 +4,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); @@ -55,6 +56,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);