[Tarantool-patches] [PATCH] console: check on_shutdown() before exit
Roman Khabibov
roman.habibov at tarantool.org
Fri Apr 17 14:36:32 MSK 2020
Hi! Thanks for the review.
@ChangeLog
- Fix bug when on_shutdown triggers weren’t executed after EOF.
> On Apr 17, 2020, at 09:55, Kirill Yukhin <kyukhin at tarantool.org> wrote:
>
> Hello,
>
> On 12 апр 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.
>>
>> Closes #4703
>> ---
>> src/main.cc | 6 +++++
>> test/box/on_shutdown.result | 42 +++++++++++++++++++++++++++++++++++
>
> Please extract the testcase into separate file.
>
> --
> Regards, Kirill Yukhin
Done.
commit 8f419619d22a8ec0882afb158db6484bb0ea51c9 (HEAD -> romanhabibov/gh-4703_on_shutdown, origin/romanhabibov/gh-4703_on_shutdown)
Author: Roman Khabibov <roman.habibov at tarantool.org>
Date: Fri Apr 10 14:31:17 2020 +0300
console: check on_shutdown() before exit
Add check that on_shutdown() triggers were called before exit,
because in case of EOF or Ctrl+D (no signals) they were ignored.
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)
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 = require('test_run')
+ | ---
+ | ...
+fio = require("fio")
+ | ---
+ | ...
+test_run = env.new()
+ | ---
+ | ...
+
+--
+-- gh-4703: Make sure that on_shutdown triggers are executed after
+-- EOF.
+--
+file_name = "on_shutdown_triggered.txt"
+ | ---
+ | ...
+test_run:cmd("setopt delimiter ';'");
+ | ---
+ | - true
+ | ...
+on_shutdown_cmd = "box.ctl.on_shutdown(function() local fio = require('fio') "..
+ "fio.open('"..file_name.."', "..
+ "{'O_CREAT', 'O_TRUNC', 'O_WRONLY'}, 777):close() end)";
+ | ---
+ | ...
+test_run:cmd("setopt delimiter ''");
+ | ---
+ | - true
+ | ...
+server = io.popen('tarantool -i', 'w')
+ | ---
+ | ...
+server:write(on_shutdown_cmd)
+ | ---
+ | - true
+ | ...
+server:close()
+ | ---
+ | - true
+ | ...
+fio.path.lexists(file_name) == 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 = require('test_run')
+fio = require("fio")
+test_run = env.new()
+
+--
+-- gh-4703: Make sure that on_shutdown triggers are executed after
+-- EOF.
+--
+file_name = "on_shutdown_triggered.txt"
+test_run:cmd("setopt delimiter ';'");
+on_shutdown_cmd = "box.ctl.on_shutdown(function() local fio = require('fio') "..
+ "fio.open('"..file_name.."', "..
+ "{'O_CREAT', 'O_TRUNC', 'O_WRONLY'}, 777):close() end)";
+test_run:cmd("setopt delimiter ''");
+server = io.popen('tarantool -i', 'w')
+server:write(on_shutdown_cmd)
+server:close()
+fio.path.lexists(file_name) == true
+os.remove(file_name)
More information about the Tarantool-patches
mailing list