From fb13b1a86d2099bf2078007f0adf30cc526c4ffa Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov@gmail.com>
Date: Tue, 28 May 2019 23:37:42 +0300
Subject: [PATCH] box/lua/console: Fix hang in case of cancelling console fiber

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 085aedfaf8..cefe5d8637 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();
 	}
 
-- 
GitLab