diff --git a/src/lua/init.cc b/src/lua/init.cc index 423067d478b252254f7708cf5f1312ec3bea248e..fb4961d37a4c6bc97d92e13de5f8f37fcd576855 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -1513,6 +1513,13 @@ load_init_script(va_list ap) { struct lua_State *L = va_arg(ap, struct lua_State *); + /* + * Return control to tarantool_lua_load_init_script. + * tarantool_lua_load_init_script when will start an auxiliary event + * loop and re-schedule this fiber. + */ + fiber_sleep(0.0); + char path[PATH_MAX + 1]; snprintf(path, PATH_MAX, "%s/%s", cfg.script_dir, TARANTOOL_LUA_INIT_SCRIPT); @@ -1530,6 +1537,12 @@ load_init_script(va_list ap) * The file doesn't exist. It's OK, tarantool may * have no init file. */ + + /* + * Lua script finished. Stop the auxiliary event loop and + * return control back to tarantool_lua_load_init_script. + */ + ev_break(EVBREAK_ALL); } /** @@ -1573,6 +1586,13 @@ tarantool_lua_load_init_script(struct lua_State *L) struct fiber *loader = fiber_new(TARANTOOL_LUA_INIT_SCRIPT, load_init_script); fiber_call(loader, L); + + /* + * Run an auxiliary event loop to re-schedule load_init_script fiber. + * When this fiber finishes, it will call ev_break to stop the loop. + */ + ev_run(0); + /* Outside the startup file require() or ffi are not * allowed. */ diff --git a/test/box/test_init.lua b/test/box/test_init.lua index 61b0ed08709bfba288bb051a352c01ce95ebddc1..c56b969341976cb919a82599f644baf84dfb5542 100644 --- a/test/box/test_init.lua +++ b/test/box/test_init.lua @@ -38,3 +38,11 @@ box.fiber.resume(fiber) -- box.insert(0, 2, 4, 8, 16) + +-- +-- A test case for https://github.com/tarantool/tarantool/issues/53 +-- + +assert (require ~= nil) +box.fiber.sleep(0.0) +assert (require ~= nil)