Skip to content

Commit d7e10ce

Browse files
authored
garbage collecting connection and no more ngx.timer - memory leak (#2)
1 parent 4ec0cad commit d7e10ce

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/lua/api-gateway/zmq/ZeroMQLogger.lua

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ local setmetatable = setmetatable
2424
local error = error
2525
local ffi = require "ffi"
2626
local ffi_new = ffi.new
27-
local ffi_str = ffi.string
28-
local C = ffi.C
2927
local zmqlib = ffi.load("zmq")
3028
local czmq = ffi.load("czmq")
3129

@@ -68,26 +66,10 @@ ffi.cdef[[
6866

6967
local ctx_v = czmq.zctx_new()
7068
local ctx = ffi_new("zctx_t *", ctx_v)
71-
local socketInst
72-
73-
local check_worker_delay = 5
74-
local function check_worker_process(premature)
75-
if not premature then
76-
local ok, err = ngx.timer.at(check_worker_delay, check_worker_process)
77-
if not ok then
78-
ngx.log(ngx.ERR, "failed to create timer to check worker process: ", err)
79-
end
80-
else
81-
ngx.log(ngx.INFO, "Terminating ZMQ context due to worker termination ...")
82-
-- this should be called when the worker is stopped
83-
zmqlib.zmq_ctx_destroy(ctx)
84-
end
85-
end
8669

87-
local ok, err = ngx.timer.at(check_worker_delay, check_worker_process)
88-
if not ok then
89-
ngx.log(ngx.ERR, "failed to create timer to check worker process: ", err)
90-
end
70+
--- garbage collect with destroy
71+
ffi.gc(ctx, zmqlib.zmq_ctx_destroy)
72+
9173

9274
function _M.new(self)
9375
return setmetatable({}, mt)

0 commit comments

Comments
 (0)