aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2018-03-16 22:26:15 +0000
committerMatthew Wild <mwild1@gmail.com>2018-03-16 22:26:15 +0000
commit5c0a12d4d1269e690a4b673cec9a95d0bb13dd9d (patch)
tree938421cd99e579bdd55b118790b6cd61d04afb92 /util
parent2f1f98e1b5cd5dac6fb792ab34da7b767ffa8cd1 (diff)
downloadprosody-5c0a12d4d1269e690a4b673cec9a95d0bb13dd9d.tar.gz
prosody-5c0a12d4d1269e690a4b673cec9a95d0bb13dd9d.zip
util.async: Ensure runner is left in correct state after out-of-main-loop error (+tests)
Diffstat (limited to 'util')
-rw-r--r--util/async.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/async.lua b/util/async.lua
index 25236b11..3a75e1c1 100644
--- a/util/async.lua
+++ b/util/async.lua
@@ -17,13 +17,18 @@ local function runner_continue(thread)
end
local ok, state, runner = coroutine.resume(thread);
if not ok then
+ local err = state;
-- Running the coroutine failed, which means we have to find the runner manually,
-- in order to inform the error handler
local level = 0;
while debug.getinfo(thread, level, "") do level = level + 1; end
ok, runner = debug.getlocal(thread, level-1, 1);
local error_handler = runner.watchers.error;
- if error_handler then error_handler(runner, debug.traceback(thread, state)); end
+ if error_handler then error_handler(runner, debug.traceback(thread, err)); end
+ local ready_handler = runner.watchers.ready;
+ runner.state, runner.thread = "ready", nil;
+ if ready_handler then ready_handler(runner); end
+ runner.notified_state = "ready";
elseif state == "ready" then
-- If state is 'ready', it is our responsibility to update runner.state from 'waiting'.
-- We also have to :run(), because the queue might have further items that will not be