Skip to content

Commit

Permalink
garbage collecting connection and no more ngx.timer - memory leak (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
atrifan authored Aug 8, 2018
1 parent 4ec0cad commit d7e10ce
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions src/lua/api-gateway/zmq/ZeroMQLogger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d7e10ce

Please sign in to comment.