From db81b1e1f051b9c84ff5b63c34145dcba5b31ce7 Mon Sep 17 00:00:00 2001 From: David Ortiz Date: Mon, 2 Jul 2018 17:50:31 +0200 Subject: [PATCH] policy/3scale_batcher: define __gc to avoid leaving pending reports --- .../apicast/policy/3scale_batcher/3scale_batcher.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua b/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua index 7ff5c1bdb..35ceeccbd 100644 --- a/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua +++ b/gateway/src/apicast/policy/3scale_batcher/3scale_batcher.lua @@ -15,10 +15,20 @@ local ipairs = ipairs local default_auths_ttl = 10 local default_batch_reports_seconds = 10 -local _M = policy.new('Caching policy') +local _M, mt = policy.new('Caching policy') local new = _M.new +mt.__gc = function(self) + -- Instances of this policy are garbage-collected when the config is + -- reloaded. We need to ensure that the TimerTask instance schedules another + -- run before that so we do not leave any pending reports. + + if self.timer_task then + self.timer_task:cancel(true) + end +end + function _M.new(config) local self = new(config)