diff --git a/src/lua/init.cc b/src/lua/init.cc index 8282ef1ef82eaaa5110ebd062cdba4b814d6e43f..11b6e4cfdd711fa238ff9c1a326f61880c01f4bc 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -517,6 +517,10 @@ box_lua_fiber_run(va_list ap __attribute__((unused))) cleanup(); } catch (const FiberCancelException& e) { + if (box_lua_fiber_get_coro(L, fiber)) { + struct fiber *caller = box_lua_fiber_get_caller(L); + fiber_wakeup(caller); + } box_lua_fiber_clear_coro(tarantool_L, fiber); /* * Note: FiberCancelException leaves garbage on @@ -638,14 +642,17 @@ lbox_fiber_resume(struct lua_State *L) */ fiber_yield_to(f); /* - * The called fiber could have done only 3 things: + * The called fiber could have done 4 things: * - yielded to us (then we should grab its return) * - completed (grab return values, wake up the fiber, * so that it can die) * - detached (grab return values, wakeup the fiber so it * can continue). + * - got cancelled (return) */ - assert(f->fid == fid); + if (f->fid != fid) + luaL_error(L, "fiber.resume(): the child fiber got cancelled"); + tarantool_lua_set_out(child_L, NULL); /* Find out the state of the child fiber. */ enum fiber_state child_state = (enum fiber_state) lua_tointeger(child_L, -1); diff --git a/test/box/fiber.result b/test/box/fiber.result index 41209e7f0c3fd9d85b2c4fc9cbbe397e78fe03cf..684ca93c6d9839bf70f610f410db35e8eb002828 100644 --- a/test/box/fiber.result +++ b/test/box/fiber.result @@ -209,3 +209,13 @@ lua box.fiber.find('test') --- - nil ... +lua f = box.fiber.create(function() box.fiber.cancel(box.fiber.self()) end) +--- +... +lua box.fiber.resume(f) +--- +error: 'fiber.resume(): the child fiber got cancelled' +... +lua f = nil +--- +... diff --git a/test/box/fiber.test b/test/box/fiber.test index 3d3e92a19d0ca4c1f663d0da3567f08197d2de87..491005c4b9f80367eee49553dc3152b6b1c0cc3a 100644 --- a/test/box/fiber.test +++ b/test/box/fiber.test @@ -83,3 +83,8 @@ exec admin "lua box.space[0]:truncate()" # https://github.com/tarantool/tarantool/issues/33 exec admin "lua box.fiber.find()" exec admin "lua box.fiber.find('test')" +# https://github.com/tarantool/tarantool/issues/131 +# box.fiber.resume(box.fiber.cancel()) -- hang +exec admin "lua f = box.fiber.create(function() box.fiber.cancel(box.fiber.self()) end)" +exec admin "lua box.fiber.resume(f)" +exec admin "lua f = nil"