From e7436bfa95a113785b67d53d14d190f5c0020bcf Mon Sep 17 00:00:00 2001 From: hong Date: Sat, 3 Feb 2018 15:43:33 +0800 Subject: [PATCH 1/3] skynet.response() leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit datasheet在monitor接口里面产生的reponse在release接口里面没有释放 --- lualib/skynet/datasheet/builder.lua | 31 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lualib/skynet/datasheet/builder.lua b/lualib/skynet/datasheet/builder.lua index f3ffdf2a..681af023 100644 --- a/lualib/skynet/datasheet/builder.lua +++ b/lualib/skynet/datasheet/builder.lua @@ -70,7 +70,7 @@ local datasheet = {} local handles = {} -- handle:{ ref:count , name:name , collect:resp } local dataset = {} -- name:{ handle:handle, monitor:{monitors queue} } -local function releasehandle(handle) +local function releasehandle(source, handle) local h = handles[handle] h.ref = h.ref - 1 if h.ref == 0 and h.collect then @@ -78,10 +78,12 @@ local function releasehandle(handle) h.collect = nil handles[handle] = nil end + local t=dataset[h.name] + t.monitor[source]=nil end -- from builder, create or update handle -function datasheet.update(name, handle) +function datasheet.update(source, name, handle) local t = dataset[name] if not t then -- new datasheet @@ -89,11 +91,11 @@ function datasheet.update(name, handle) dataset[name] = t handles[handle] = { ref = 1, name = name } else - t.handle = handle -- report update to customers - handles[handle] = { ref = 1 + #t.monitor, name = name } + handles[handle] = { ref = handles[t.handle].ref, name = name } + t.handle = handle - for k,v in ipairs(t.monitor) do + for k,v in pairs(t.monitor) do v(true, handle) t.monitor[k] = nil end @@ -102,7 +104,7 @@ function datasheet.update(name, handle) end -- from customers -function datasheet.query(name) +function datasheet.query(source, name) local t = assert(dataset[name], "create data first") local handle = t.handle local h = handles[handle] @@ -111,25 +113,26 @@ function datasheet.query(name) end -- from customers, monitor handle change -function datasheet.monitor(handle) +function datasheet.monitor(source, handle) local h = assert(handles[handle], "Invalid data handle") local t = dataset[h.name] if t.handle ~= handle then -- already changes skynet.ret(skynet.pack(t.handle)) else h.ref = h.ref + 1 - table.insert(t.monitor, skynet.response()) + assert(not t.monitor[source]) + t.monitor[source]=handle end end -- from customers, release handle , ref count - 1 -function datasheet.release(handle) +function datasheet.release(source, handle) -- send message, don't ret - releasehandle(handle) + releasehandle(source, handle) end -- from builder, monitor handle release -function datasheet.collect(handle) +function datasheet.collect(source, handle) local h = assert(handles[handle], "Invalid data handle") if h.ref == 0 then handles[handle] = nil @@ -140,8 +143,8 @@ function datasheet.collect(handle) end end -skynet.dispatch("lua", function(_,_,cmd,...) - datasheet[cmd](...) +skynet.dispatch("lua", function(_,source,cmd,...) + datasheet[cmd](source,...) end) skynet.info_func(function() @@ -155,7 +158,7 @@ skynet.info_func(function() tmp[v.handle] = nil info[k] = { handle = v.handle, - monitors = #v.monitor, + monitors = h.ref, } end for k,v in pairs(tmp) do From 2dd5a06616c9283bc9fb510f6b97cae110eae40d Mon Sep 17 00:00:00 2001 From: hong Date: Sat, 3 Feb 2018 15:49:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8A=84=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lualib/skynet/datasheet/builder.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lualib/skynet/datasheet/builder.lua b/lualib/skynet/datasheet/builder.lua index 681af023..25806de6 100644 --- a/lualib/skynet/datasheet/builder.lua +++ b/lualib/skynet/datasheet/builder.lua @@ -121,7 +121,7 @@ function datasheet.monitor(source, handle) else h.ref = h.ref + 1 assert(not t.monitor[source]) - t.monitor[source]=handle + t.monitor[source]=skynet.response() end end From ab13305b64dd14dadcf70b174fa3db2189264989 Mon Sep 17 00:00:00 2001 From: hong Date: Mon, 5 Feb 2018 10:18:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?monitor=E4=B8=AD=E4=B8=8D=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?ref?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lualib/skynet/datasheet/builder.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lualib/skynet/datasheet/builder.lua b/lualib/skynet/datasheet/builder.lua index 25806de6..1683a105 100644 --- a/lualib/skynet/datasheet/builder.lua +++ b/lualib/skynet/datasheet/builder.lua @@ -119,7 +119,6 @@ function datasheet.monitor(source, handle) if t.handle ~= handle then -- already changes skynet.ret(skynet.pack(t.handle)) else - h.ref = h.ref + 1 assert(not t.monitor[source]) t.monitor[source]=skynet.response() end