Tarantool development patches archive
 help / color / mirror / Atom feed
From: Roman Khabibov <roman.habibov@tarantool.org>
To: Kirill Yukhin <kyukhin@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
Date: Fri, 17 Apr 2020 14:36:32 +0300	[thread overview]
Message-ID: <DE24C4E8-8C8A-4A7D-BE9E-483EA26920E2@tarantool.org> (raw)
In-Reply-To: <20200417065554.ai2pj4n3v5lfbdq7@tarantool.org>

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@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@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)

  reply	other threads:[~2020-04-17 11:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11 23:10 Roman Khabibov
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 [this message]
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=DE24C4E8-8C8A-4A7D-BE9E-483EA26920E2@tarantool.org \
    --to=roman.habibov@tarantool.org \
    --cc=kyukhin@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