Skip to content

Commit

Permalink
log error when forget response a session. Add skynet.ignoreret()
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu committed May 24, 2018
1 parent 85ec428 commit 2fde0a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
29 changes: 22 additions & 7 deletions lualib/skynet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ end
local session_id_coroutine = {}
local session_coroutine_id = {}
local session_coroutine_address = {}
local session_response = {}
local unresponse = {}

local wakeup_queue = {}
Expand Down Expand Up @@ -76,6 +75,7 @@ local function dispatch_error_queue()
end

local function _error_dispatch(error_session, error_source)
skynet.ignoreret() -- don't return for error
if error_session == 0 then
-- service is down
-- Don't remove from watching_service , because user may call dead service
Expand Down Expand Up @@ -105,6 +105,14 @@ local function co_create(f)
co = coroutine.create(function(...)
f(...)
while true do
local session = session_coroutine_id[co]
if session and session ~= 0 then
local source = debug.getinfo(f,"S")
skynet.error(string.format("Maybe forgot response session %s from %s : %s:%d",
session,
skynet.address(session_coroutine_address[co]),
source.source, source.linedefined))
end
f = nil
coroutine_pool[#coroutine_pool+1] = co
f = coroutine_yield "EXIT"
Expand Down Expand Up @@ -162,17 +170,17 @@ function suspend(co, result, command, param, size)
sleep_session[co] = param
elseif command == "RETURN" then
local co_session = session_coroutine_id[co]
session_coroutine_id[co] = nil
if co_session == 0 then
if size ~= nil then
c.trash(param, size)
end
return suspend(co, coroutine_resume(co, false)) -- send don't need ret
end
local co_address = session_coroutine_address[co]
if param == nil or session_response[co] then
if param == nil or not co_session then
error(debug.traceback(co))
end
session_response[co] = true
local ret
if not dead_service[co_address] then
ret = c.send(co_address, skynet.PTYPE_RESPONSE, co_session, param, size) ~= nil
Expand All @@ -187,10 +195,11 @@ function suspend(co, result, command, param, size)
return suspend(co, coroutine_resume(co, ret))
elseif command == "RESPONSE" then
local co_session = session_coroutine_id[co]
local co_address = session_coroutine_address[co]
if session_response[co] then
if not co_session then
error(debug.traceback(co))
end
session_coroutine_id[co] = nil
local co_address = session_coroutine_address[co]
local f = param
local function response(ok, ...)
if ok == "TEST" then
Expand Down Expand Up @@ -232,7 +241,6 @@ function suspend(co, result, command, param, size)
return ret
end
watching_service[co_address] = watching_service[co_address] + 1
session_response[co] = true
unresponse[response] = true
return suspend(co, coroutine_resume(co, response))
elseif command == "EXIT" then
Expand All @@ -242,14 +250,17 @@ function suspend(co, result, command, param, size)
release_watching(address)
session_coroutine_id[co] = nil
session_coroutine_address[co] = nil
session_response[co] = nil
end
elseif command == "QUIT" then
-- service exit
return
elseif command == "USER" then
-- See skynet.coutine for detail
error("Call skynet.coroutine.yield out of skynet.coroutine.resume\n" .. debug.traceback(co))
elseif command == "IGNORERET" then
-- We use session for other uses
session_coroutine_id[co] = nil
return suspend(co, coroutine_resume(co))
elseif command == nil then
-- debug trace
return
Expand Down Expand Up @@ -405,6 +416,10 @@ function skynet.ret(msg, sz)
return coroutine_yield("RETURN", msg, sz)
end

function skynet.ignoreret()
coroutine_yield "IGNORERET"
end

function skynet.response(pack)
pack = pack or skynet.pack
return coroutine_yield("RESPONSE", pack)
Expand Down
2 changes: 1 addition & 1 deletion test/testdeadcall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ else
local dead = skynet.newservice(SERVICE_NAME, "dead") -- launch self in dead mode

skynet.timeout(0, skynet.exit) -- exit after a while, so the call never return
skynet.call(dead, "lua", "whould not return")
skynet.call(dead, "lua", "would not return")
end)
end

0 comments on commit 2fde0a0

Please sign in to comment.