From d7e10ce2d4b79a5587cf871d9b0c5443c2f6ee5d Mon Sep 17 00:00:00 2001 From: Alexandru Trifan Date: Wed, 8 Aug 2018 11:36:56 +0300 Subject: [PATCH] garbage collecting connection and no more ngx.timer - memory leak (#2) --- src/lua/api-gateway/zmq/ZeroMQLogger.lua | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/lua/api-gateway/zmq/ZeroMQLogger.lua b/src/lua/api-gateway/zmq/ZeroMQLogger.lua index 151e9d4..ea630ac 100644 --- a/src/lua/api-gateway/zmq/ZeroMQLogger.lua +++ b/src/lua/api-gateway/zmq/ZeroMQLogger.lua @@ -24,8 +24,6 @@ local setmetatable = setmetatable local error = error local ffi = require "ffi" local ffi_new = ffi.new -local ffi_str = ffi.string -local C = ffi.C local zmqlib = ffi.load("zmq") local czmq = ffi.load("czmq") @@ -68,26 +66,10 @@ ffi.cdef[[ local ctx_v = czmq.zctx_new() local ctx = ffi_new("zctx_t *", ctx_v) -local socketInst - -local check_worker_delay = 5 -local function check_worker_process(premature) - if not premature then - local ok, err = ngx.timer.at(check_worker_delay, check_worker_process) - if not ok then - ngx.log(ngx.ERR, "failed to create timer to check worker process: ", err) - end - else - ngx.log(ngx.INFO, "Terminating ZMQ context due to worker termination ...") - -- this should be called when the worker is stopped - zmqlib.zmq_ctx_destroy(ctx) - end -end -local ok, err = ngx.timer.at(check_worker_delay, check_worker_process) -if not ok then - ngx.log(ngx.ERR, "failed to create timer to check worker process: ", err) -end +--- garbage collect with destroy +ffi.gc(ctx, zmqlib.zmq_ctx_destroy) + function _M.new(self) return setmetatable({}, mt)