From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (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 C442F4696C3 for ; Fri, 17 Apr 2020 14:36:33 +0300 (MSK) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3594.4.19\)) From: Roman Khabibov In-Reply-To: <20200417065554.ai2pj4n3v5lfbdq7@tarantool.org> Date: Fri, 17 Apr 2020 14:36:32 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <20200411231034.95903-1-roman.habibov@tarantool.org> <20200417065554.ai2pj4n3v5lfbdq7@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kirill Yukhin Cc: tarantool-patches@dev.tarantool.org Hi! Thanks for the review. @ChangeLog - Fix bug when on_shutdown triggers weren=E2=80=99t executed after EOF. > On Apr 17, 2020, at 09:55, Kirill Yukhin = wrote: >=20 > Hello, >=20 > On 12 =D0=B0=D0=BF=D1=80 02:10, Roman Khabibov wrote: >> Add check that on_shutdown() triggers were called before exit, >> because in case of EOF or Ctrl+D (no signals) they were ignored. >>=20 >> Closes #4703 >> --- >> src/main.cc | 6 +++++ >> test/box/on_shutdown.result | 42 = +++++++++++++++++++++++++++++++++++ >=20 > Please extract the testcase into separate file. >=20 > -- > Regards, Kirill Yukhin Done. commit 8f419619d22a8ec0882afb158db6484bb0ea51c9 (HEAD -> = romanhabibov/gh-4703_on_shutdown, = origin/romanhabibov/gh-4703_on_shutdown) Author: Roman Khabibov Date: Fri Apr 10 14:31:17 2020 +0300 console: check on_shutdown() before exit =20 Add check that on_shutdown() triggers were called before exit, because in case of EOF or Ctrl+D (no signals) they were ignored. =20 Closes #4703 diff --git a/src/main.cc b/src/main.cc index bb0794dfe..a2cea3d40 100644 --- a/src/main.cc +++ b/src/main.cc @@ -902,6 +902,12 @@ main(int argc, char **argv) =20 if (start_loop) say_crit("exiting the event loop"); + /* + * If Tarantool was stopped using Ctrl+D, then we need to + * call on_shutdown triggers, because Ctrl+D causes not + * any signals. + */ + tarantool_exit(exit_code); /* freeing resources */ tarantool_free(); return exit_code; diff --git a/test/box/gh-4703-on_shutdown-bug.result = b/test/box/gh-4703-on_shutdown-bug.result new file mode 100644 index 000000000..7c1aae2ba --- /dev/null +++ b/test/box/gh-4703-on_shutdown-bug.result @@ -0,0 +1,50 @@ +-- test-run result file version 2 +env =3D require('test_run') + | --- + | ... +fio =3D require("fio") + | --- + | ... +test_run =3D env.new() + | --- + | ... + +-- +-- gh-4703: Make sure that on_shutdown triggers are executed after +-- EOF. +-- +file_name =3D "on_shutdown_triggered.txt" + | --- + | ... +test_run:cmd("setopt delimiter ';'"); + | --- + | - true + | ... +on_shutdown_cmd =3D "box.ctl.on_shutdown(function() local fio =3D = require('fio') ".. + "fio.open('"..file_name.."', ".. + "{'O_CREAT', 'O_TRUNC', 'O_WRONLY'}, 777):close() = end)"; + | --- + | ... +test_run:cmd("setopt delimiter ''"); + | --- + | - true + | ... +server =3D io.popen('tarantool -i', 'w') + | --- + | ... +server:write(on_shutdown_cmd) + | --- + | - true + | ... +server:close() + | --- + | - true + | ... +fio.path.lexists(file_name) =3D=3D true + | --- + | - true + | ... +os.remove(file_name) + | --- + | - true + | ... diff --git a/test/box/gh-4703-on_shutdown-bug.test.lua = b/test/box/gh-4703-on_shutdown-bug.test.lua new file mode 100755 index 000000000..2b15277db --- /dev/null +++ b/test/box/gh-4703-on_shutdown-bug.test.lua @@ -0,0 +1,19 @@ +env =3D require('test_run') +fio =3D require("fio") +test_run =3D env.new() + +-- +-- gh-4703: Make sure that on_shutdown triggers are executed after +-- EOF. +-- +file_name =3D "on_shutdown_triggered.txt" +test_run:cmd("setopt delimiter ';'"); +on_shutdown_cmd =3D "box.ctl.on_shutdown(function() local fio =3D = require('fio') ".. + "fio.open('"..file_name.."', ".. + "{'O_CREAT', 'O_TRUNC', 'O_WRONLY'}, 777):close() = end)"; +test_run:cmd("setopt delimiter ''"); +server =3D io.popen('tarantool -i', 'w') +server:write(on_shutdown_cmd) +server:close() +fio.path.lexists(file_name) =3D=3D true +os.remove(file_name)=