Skip to content
Snippets Groups Projects
Commit dd65d5c6 authored by Ilya Verbin's avatar Ilya Verbin Committed by Vladimir Davydov
Browse files

main: allow spurious wakeups in on_shutdown_f

It will yield until the is_shutting_down flag is set by tarantool_exit().
This allows to get rid of the FIBER_IS_CANCELLABLE flag, which is no
longer used anywhere in Tarantool.

Part of #7166

NO_DOC=internal
NO_CHANGELOG=internal
parent a6b48f14
No related branches found
No related tags found
No related merge requests found
......@@ -147,6 +147,10 @@ on_shutdown_f(va_list ap)
if (ev_depth(loop()) == 0)
fiber_sleep(0.0);
/* Handle spurious wakeups. */
while (!is_shutting_down)
fiber_yield();
if (trigger_fiber_run(&box_on_shutdown_trigger_list, NULL,
on_shutdown_trigger_timeout) != 0) {
say_error("on_shutdown triggers failed");
......@@ -172,7 +176,7 @@ tarantool_exit(int code)
is_shutting_down = true;
exit_code = code;
box_broadcast_fmt("box.shutdown", "%b", true);
fiber_call(on_shutdown_fiber);
fiber_wakeup(on_shutdown_fiber);
}
static void
......@@ -770,16 +774,9 @@ main(int argc, char **argv)
box_lua_init(tarantool_L);
/*
* Reserve a fiber to run on_shutdown triggers.
* Make sure the fiber is non-cancellable so that
* it doesn't get woken up from Lua unintentionally.
*/
struct fiber_attr attr;
fiber_attr_create(&attr);
attr.flags |= FIBER_IS_SYSTEM;
attr.flags &= ~FIBER_IS_CANCELLABLE;
on_shutdown_fiber = fiber_new_ex("on_shutdown",
&attr,
on_shutdown_f);
on_shutdown_fiber = fiber_new_system("on_shutdown",
on_shutdown_f);
if (on_shutdown_fiber == NULL)
diag_raise();
......
local t = require('luatest')
local g = t.group('gh-7166')
-- Check that wake up of the shutdown fiber doesn't crash Tarantool
g.test_wakeup_on_shutdown_fiber = function()
local lt_fiber = require('test.luatest_helpers.fiber')
local f = lt_fiber.find_by_name('on_shutdown')
f:wakeup()
end
local fiber = require('fiber')
-- Searches for a fiber with the specified name and returns the fiber object
local function find_by_name(name)
for id, f in pairs(fiber.info()) do
if f.name == name then
return fiber.find(id)
end
end
return nil
end
return {
find_by_name = find_by_name
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment