From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Return-Path: Date: Tue, 28 May 2019 23:37:42 +0300 From: Cyrill Gorcunov Subject: [PATCH] box/lua/console: Fix hang in case of cancelling console fiber Message-ID: <20190528203742.GR11013@uranus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline To: tarantool Cc: Alexander Turenko , Kirill Yukhin , Konstantin Osipov , Vladimir Davydov List-ID: Since commit f42596a2266479337b6d101befaae6fbf0943f37 we've started to test if a fiber is cancelled in coio_wait. This may hang interactive console with simple fiber.kill(fiber.self()) call. Sane users don't do such tricks and this affects interactive console mode only but still to be on a safe side lets exit if someone occasionally killed the console fiber. Notes: - such exit may ruine terminals settings and one need to reset it after; - the issue happens on interactive console only so I didn't find a way for automatic test and tested manually. --- src/box/lua/console.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/box/lua/console.c b/src/box/lua/console.c index 085aedfaf..cefe5d863 100644 --- a/src/box/lua/console.c +++ b/src/box/lua/console.c @@ -229,8 +229,15 @@ lbox_console_readline(struct lua_State *L) top = lua_gettop(L); while (top == lua_gettop(L)) { while (coio_wait(STDIN_FILENO, COIO_READ, - TIMEOUT_INFINITY) == 0); - + TIMEOUT_INFINITY) == 0) { + /* + * Make sure the user of interactive + * console has not hanged us, otherwise + * we might spin here forever eating + * the whole cpu time. + */ + luaL_testcancel(L); + } rl_callback_read_char(); } -- 2.20.1