diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-10 19:05:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-10 19:05:12 +0800 |
commit | e642773d31b415ff79c6a682486a3e7aaa2f8a86 (patch) | |
tree | 5ce6380490730f72fe3599ea0c28738fa59f57b5 | |
parent | 47e84995fda8b3ac1a196cb2c157d45ea9e3dbc0 (diff) | |
download | lua-language-server-e642773d31b415ff79c6a682486a3e7aaa2f8a86.zip |
对意外挂起的任务进行检查
-rw-r--r-- | script-beta/await.lua | 2 | ||||
-rw-r--r-- | script-beta/proto/proto.lua | 18 |
2 files changed, 16 insertions, 4 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua index 7134716b..30cbf993 100644 --- a/script-beta/await.lua +++ b/script-beta/await.lua @@ -107,7 +107,7 @@ function m.step() local clock = os.clock() waker() local passed = os.clock() - clock - if passed > 0.01 then + if passed > 0.1 then log.warn(('Await step takes [%.3f] sec.\n%s'):format(passed, buildInfo(waker))) end return true diff --git a/script-beta/proto/proto.lua b/script-beta/proto/proto.lua index af0515ec..7b6b0087 100644 --- a/script-beta/proto/proto.lua +++ b/script-beta/proto/proto.lua @@ -4,6 +4,7 @@ local await = require 'await' local pub = require 'pub' local jsonrpc = require 'jsonrpc' local ErrorCodes = require 'define.ErrorCodes' +local timer = require 'timer' local reqCounter = util.counter() @@ -11,6 +12,7 @@ local m = {} m.ability = {} m.waiting = {} +m.running = {} function m.getMethodName(proto) if proto.method:sub(1, 2) == '$/' then @@ -89,10 +91,16 @@ function m.doMethod(proto) end return end + if proto.id then + m.running[proto.id] = method + end await.create(function () log.debug('Start method:', method) - local ok, res, passed + local clock = os.clock() + local ok, res + -- 任务可能在执行过程中被中断,通过close来捕获 local response <close> = util.defer(function () + local passed = os.clock() - clock if passed > 0.2 then log.debug(('Method [%s] takes [%.3f]sec.'):format(method, passed)) end @@ -105,10 +113,9 @@ function m.doMethod(proto) else m.responseErr(proto.id, ErrorCodes.InternalError, res) end + m.running[proto.id] = nil end) - local clock = os.clock() ok, res = xpcall(abil, log.error, proto.params) - passed = os.clock() - clock end) end @@ -133,6 +140,11 @@ function m.listen() io.stdin:setvbuf 'no' io.stdout:setvbuf 'no' pub.task('loadProto') + timer.loop(10, function () + for id, name in pairs(m.running) do + m.responseErr(id, ErrorCodes.InternalError, ('Task [%s] failed unexpected!'):format(name)) + end + end) end return m |