Skip to content

Commit

Permalink
fix reload之后,旧服务一直触发watch
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Dec 6, 2024
1 parent cd7bfdb commit fb8025e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lualib/skynet-fly/client/contriner_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local skynet = require "skynet"
local module_info = require "skynet-fly.etc.module_info"
local skynet_util = require "skynet-fly.utils.skynet_util"
local table_util = require "skynet-fly.utils.table_util"
local wait = require "skynet-fly.time_extend.wait"
local setmetatable = setmetatable
local assert = assert
local pairs = pairs
Expand Down Expand Up @@ -34,6 +35,7 @@ local g_querycbed_map = {} --查询到地址已执行回调列表
local g_updated_map = {} --更新地址的回调列表
local g_always_swtich_map = {}--总能切换的modulename服务,不受is_close_swtich限制
local g_pre_gc_time = 0 --上次调用gc的时间
local g_wait = wait:new()

local SERVICE_NAME = SERVICE_NAME
--弱引用原表
Expand Down Expand Up @@ -106,6 +108,7 @@ local function monitor(t,key)
while not IS_CLOSE do
local old_version = g_mod_svr_version_map[key]
local id_list,name_id_list,version = skynet.call(get_contriner_mgr_addr(), 'lua', 'watch', SELF_ADDRESS, key, old_version)
skynet.error("monitor ", key)
if not is_close_swtich or g_always_swtich_map[key] then
add_id_list_week(key,id_list)
register_visitor(id_list)
Expand All @@ -117,6 +120,9 @@ local function monitor(t,key)
if updated then
skynet.fork(call_back_updated, updated)
end
else
--等待开放swtich
g_wait:wait("open_swtich")
end
end
end
Expand Down Expand Up @@ -225,6 +231,7 @@ end
--开启服务切换
function M:open_switch()
is_close_swtich = false
g_wait:wakeup("open_switch")
end

skynet.init(function()
Expand Down
10 changes: 7 additions & 3 deletions lualib/skynet-fly/time_extend/wait.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local M = {}
local mata = {__index = M}

function M:new(time_out)
assert(time_out > 0, "time_out err")
local t = {
map = {},
list = {},
Expand All @@ -34,11 +33,16 @@ function M:wait(k)
end

local co = coroutine.running()
local ti = timer:new(self.time_out, 1, skynet.wakeup, co)
local ti = nil
if self.time_out then
ti = timer:new(self.time_out, 1, skynet.wakeup, co)
end
map[k][co] = true
tinsert(list[k], co)
skynet.wait(co)
ti:cancel()
if ti then
ti:cancel()
end
map[k][co] = nil
local ls = list[k]
for i = 1,#ls do
Expand Down

0 comments on commit fb8025e

Please sign in to comment.