From: Roman Khabibov <roman.habibov@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
Date: Sun, 12 Apr 2020 02:10:34 +0300 [thread overview]
Message-ID: <20200411231034.95903-1-roman.habibov@tarantool.org> (raw)
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 +++++++++++++++++++++++++++++++++++
test/box/on_shutdown.test.lua | 17 ++++++++++++++
3 files changed, 65 insertions(+)
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/on_shutdown.result b/test/box/on_shutdown.result
index ccbdf45cb..38af72b11 100644
--- a/test/box/on_shutdown.result
+++ b/test/box/on_shutdown.result
@@ -167,3 +167,45 @@ test_run:cmd("delete server test")
---
- true
...
+--
+-- gh-4703: Make sure that on_shutdown triggers are executed after
+-- EOF.
+--
+fio = require("fio")
+---
+...
+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):clo"..
+ "se() 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/on_shutdown.test.lua b/test/box/on_shutdown.test.lua
index 2a9143404..795887202 100644
--- a/test/box/on_shutdown.test.lua
+++ b/test/box/on_shutdown.test.lua
@@ -65,3 +65,20 @@ test_run:grep_log('test', 'signal', nil, {noreset=true})
test_run:cmd("stop server test")
test_run:cmd("cleanup server test")
test_run:cmd("delete server test")
+
+--
+-- gh-4703: Make sure that on_shutdown triggers are executed after
+-- EOF.
+--
+fio = require("fio")
+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):clo"..
+ "se() 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)
--
2.21.0 (Apple Git-122)
next reply other threads:[~2020-04-11 23:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-11 23:10 Roman Khabibov [this message]
2020-04-12 10:37 ` Cyrill Gorcunov
2020-04-15 1:57 ` Roman Khabibov
2020-04-16 14:03 ` Cyrill Gorcunov
2020-04-17 6:55 ` Kirill Yukhin
2020-04-17 11:36 ` Roman Khabibov
2020-05-08 7:20 ` Kirill Yukhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200411231034.95903-1-roman.habibov@tarantool.org \
--to=roman.habibov@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox