From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5CC2C45C307 for ; Wed, 9 Dec 2020 22:28:41 +0300 (MSK) From: Artem Starshov Date: Wed, 9 Dec 2020 22:28:35 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/2] src/lua: fix running init lua script List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Turenko Cc: tarantool-patches@dev.tarantool.org When tarantool launched with -e flag and in script after there is an error, programm hangs. This happens because shed fiber launches separate fiber for init user script and starts auxiliary event loop. It's supposed that fiber will stop this loop, but in case of error in script, fiber tries to stop a loop when the last one isn't started yet. Added a flag, which will watch is loop started and when fiber tries to call `ev_break()` we can be sure that loop is runnig already. Part of #4983 --- src/lua/init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lua/init.c b/src/lua/init.c index a0b2fc775..92bdb82c0 100644 --- a/src/lua/init.c +++ b/src/lua/init.c @@ -569,6 +569,7 @@ run_script_f(va_list ap) * never really dead. It never returns from its function. */ struct diag *diag = va_arg(ap, struct diag *); + bool aux_loop_is_run = false; /* * Load libraries and execute chunks passed by -l and -e @@ -611,6 +612,7 @@ run_script_f(va_list ap) * loop and re-schedule this fiber. */ fiber_sleep(0.0); + aux_loop_is_run = true; if (path && strcmp(path, "-") != 0 && access(path, F_OK) == 0) { /* Execute script. */ @@ -650,6 +652,13 @@ run_script_f(va_list ap) * return control back to tarantool_lua_run_script. */ end: + /* + * Auxiliary loop in tarantool_lua_run_script + * should start (ev_run()) before this fiber + * invokes ev_break(). + */ + if (!aux_loop_is_run) + fiber_sleep(0.0); ev_break(loop(), EVBREAK_ALL); return 0; -- 2.28.0