diff --git a/HISTORY.md b/HISTORY.md index 3f4d5d9d..0ca75332 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,10 @@ +v0.4.1 (2014-7-7) +----------- +* Add SERVICE_NAME in loader +* Throw error back when skynet.error +* Add skynet.task +* Bugfix for last version (harbor service bugs) + v0.4.0 (2014-6-30) ----------- * Optimize redis driver `compose_message`. diff --git a/examples/simplemonitor.lua b/examples/simplemonitor.lua index 1528bb50..ec294d21 100644 --- a/examples/simplemonitor.lua +++ b/examples/simplemonitor.lua @@ -12,7 +12,7 @@ skynet.register_protocol { local w = service_map[address] if w then for watcher in pairs(w) do - skynet.redirect(watcher, address, "error", "") + skynet.redirect(watcher, address, "error", 0, "") end service_map[address] = false end diff --git a/lualib/loader.lua b/lualib/loader.lua index 05224b92..1c4ee58a 100644 --- a/lualib/loader.lua +++ b/lualib/loader.lua @@ -3,11 +3,13 @@ for word in string.gmatch(..., "%S+") do table.insert(args, word) end +SERVICE_NAME = args[1] + local main, pattern local err = {} for pat in string.gmatch(LUA_SERVICE, "([^;]+);*") do - local filename = string.gsub(pat, "?", args[1]) + local filename = string.gsub(pat, "?", SERVICE_NAME) local f, msg = loadfile(filename) if not f then table.insert(err, msg) diff --git a/lualib/skynet.lua b/lualib/skynet.lua index 2019f530..f9d934c3 100644 --- a/lualib/skynet.lua +++ b/lualib/skynet.lua @@ -253,6 +253,13 @@ end function skynet.exit() skynet.send(".launcher","lua","REMOVE",skynet.self()) + for co, session in pairs(session_coroutine_id) do + local address = session_coroutine_address[co] + local self = skynet.self() + if session~=0 and address then + skynet.redirect(self, address, "error", session, "") + end + end c.command("EXIT") end @@ -569,12 +576,24 @@ function skynet.monitor(service, query) end assert(monitor, "Monitor launch failed") c.command("MONITOR", string.format(":%08x", monitor)) + return monitor end function skynet.mqlen() return tonumber(c.command "MQLEN") end +function skynet.task(ret) + local t = 0 + for session,co in pairs(session_id_coroutine) do + if ret then + ret[session] = debug.traceback(co) + end + t = t + 1 + end + return t +end + -- Inject internal debug framework local debug = require "skynet.debug" debug(skynet) diff --git a/lualib/skynet/debug.lua b/lualib/skynet/debug.lua index 807ee2ae..c8f51f0b 100644 --- a/lualib/skynet/debug.lua +++ b/lualib/skynet/debug.lua @@ -21,9 +21,16 @@ end function dbgcmd.STAT() local stat = {} stat.mqlen = skynet.mqlen() + stat.task = skynet.task() skynet.ret(skynet.pack(stat)) end +function dbgcmd.TASK() + local task = {} + skynet.task(task) + skynet.ret(skynet.pack(task)) +end + function dbgcmd.INFO() if internal_info_func then skynet.ret(skynet.pack(internal_info_func())) diff --git a/service-src/service_harbor.c b/service-src/service_harbor.c index f7a88f2b..fbb6406d 100644 --- a/service-src/service_harbor.c +++ b/service-src/service_harbor.c @@ -262,7 +262,8 @@ harbor_release(struct harbor *h) { struct slave *s = &h->s[i]; if (s->fd && s->status != STATUS_DOWN) { close_harbor(h,i); - report_harbor_down(h,i); + // don't call report_harbor_down. + // never call skynet_send during module exit, because of dead lock } } hash_delete(h->map); @@ -509,6 +510,9 @@ remote_send_handle(struct harbor *h, uint32_t source, uint32_t destination, int skynet_send(context, destination, source, PTYPE_ERROR, 0 , NULL, 0); skynet_error(context, "Drop message to harbor %d from %x to %x (session = %d, msgsz = %d)",harbor_id, source, destination,session,(int)sz); } else { + if (s->queue == NULL) { + s->queue = new_queue(); + } struct remote_message_header header; header.source = source; header.destination = type << HANDLE_REMOTE_SHIFT; diff --git a/service/debug_console.lua b/service/debug_console.lua index b15c3889..a587f69d 100644 --- a/service/debug_console.lua +++ b/service/debug_console.lua @@ -113,6 +113,7 @@ function COMMAND.help() snax = "lanuch a new snax service", clearcache = "clear lua code cache", service = "List unique service", + task = "task address : show service task detail", } end diff --git a/service/launcher.lua b/service/launcher.lua index b80eadc9..5c1c1a8b 100644 --- a/service/launcher.lua +++ b/service/launcher.lua @@ -38,6 +38,16 @@ function command.INFO(_, _, handle) end end +function command.TASK(_, _, handle) + handle = handle_to_address(handle) + if services[handle] == nil then + return + else + local result = skynet.call(handle,"debug","TASK") + return result + end +end + function command.KILL(_, _, handle) handle = handle_to_address(handle) skynet.kill(handle) diff --git a/test/testdeadcall.lua b/test/testdeadcall.lua index d348a411..c5d67b8c 100644 --- a/test/testdeadcall.lua +++ b/test/testdeadcall.lua @@ -14,7 +14,7 @@ end) else skynet.start(function() - local test = skynet.newservice("testdeadcall", "test") -- launch self in test mode + local test = skynet.newservice(SERVICE_NAME, "test") -- launch self in test mode print(pcall(function() skynet.send(test,"lua", "hello world") diff --git a/test/testmulticast.lua b/test/testmulticast.lua index 88f79ccb..8f084abf 100644 --- a/test/testmulticast.lua +++ b/test/testmulticast.lua @@ -27,7 +27,7 @@ skynet.start(function() local channel = mc.new() print("New channel", channel) for i=1,10 do - local sub = skynet.newservice("testmulticast", "sub") + local sub = skynet.newservice(SERVICE_NAME, "sub") skynet.call(sub, "lua", "init", channel.channel) end