Skip to content

garbage collecting connection and no more ngx.timer - memory leak #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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