Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
@ 2020-04-11 23:10 Roman Khabibov
  2020-04-12 10:37 ` Cyrill Gorcunov
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Roman Khabibov @ 2020-04-11 23:10 UTC (permalink / raw)
  To: tarantool-patches

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)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
  2020-04-11 23:10 [Tarantool-patches] [PATCH] console: check on_shutdown() before exit Roman Khabibov
@ 2020-04-12 10:37 ` Cyrill Gorcunov
  2020-04-15  1:57   ` Roman Khabibov
  2020-04-17  6:55 ` Kirill Yukhin
  2020-05-08  7:20 ` Kirill Yukhin
  2 siblings, 1 reply; 7+ messages in thread
From: Cyrill Gorcunov @ 2020-04-12 10:37 UTC (permalink / raw)
  To: Roman Khabibov; +Cc: tarantool-patches

On Sun, Apr 12, 2020 at 02:10:34AM +0300, 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

Ok, I don't see any obvious problems with the patch. Only a nit
due to coding style below.
...
> 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})
...
> +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)";

This is ugly as hell. Can we please do not split "close". Something like

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)";

Or somehow more readable? Maybe like

on_shutdown_cmd = "box.ctl.on_shutdown(function() local fio = require('fio') "..
	"local flags = {'O_CREAT', 'O_TRUNC', 'O_WRONLY'}" ..
	"local f = fio.open(mode, 777)" ..
	"f:close()"

(I'm sure I've done some typos here but you get the idea)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
  2020-04-12 10:37 ` Cyrill Gorcunov
@ 2020-04-15  1:57   ` Roman Khabibov
  2020-04-16 14:03     ` Cyrill Gorcunov
  0 siblings, 1 reply; 7+ messages in thread
From: Roman Khabibov @ 2020-04-15  1:57 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: tarantool-patches


Hi! Thanks for the review.

> On Apr 12, 2020, at 13:37, Cyrill Gorcunov <gorcunov@gmail.com> wrote:
> 
> On Sun, Apr 12, 2020 at 02:10:34AM +0300, 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
> 
> Ok, I don't see any obvious problems with the patch. Only a nit
> due to coding style below.
> ...
>> 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})
> ...
>> +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)";
> 
> This is ugly as hell. Can we please do not split "close". Something like
> 
> 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)";
> 
> Or somehow more readable? Maybe like
> 
> on_shutdown_cmd = "box.ctl.on_shutdown(function() local fio = require('fio') "..
> 	"local flags = {'O_CREAT', 'O_TRUNC', 'O_WRONLY'}" ..
> 	"local f = fio.open(mode, 777)" ..
> 	"f:close()"
> 
> (I'm sure I've done some typos here but you get the idea)
diff --git a/test/box/on_shutdown.test.lua b/test/box/on_shutdown.test.lua
index 2a9143404..d033a7ac5 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):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)

commit 6466cf42ae5755826af0c616243106a696da044a (HEAD -> 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/on_shutdown.result b/test/box/on_shutdown.result
index ccbdf45cb..8ca8fed2b 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):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/on_shutdown.test.lua b/test/box/on_shutdown.test.lua
index 2a9143404..d033a7ac5 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):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)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
  2020-04-15  1:57   ` Roman Khabibov
@ 2020-04-16 14:03     ` Cyrill Gorcunov
  0 siblings, 0 replies; 7+ messages in thread
From: Cyrill Gorcunov @ 2020-04-16 14:03 UTC (permalink / raw)
  To: Roman Khabibov; +Cc: tarantool-patches

On Wed, Apr 15, 2020 at 04:57:39AM +0300, Roman Khabibov wrote:
...
> 
> commit 6466cf42ae5755826af0c616243106a696da044a (HEAD -> 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

Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>

Hopefully I didn't miss something obvious.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
  2020-04-11 23:10 [Tarantool-patches] [PATCH] console: check on_shutdown() before exit Roman Khabibov
  2020-04-12 10:37 ` Cyrill Gorcunov
@ 2020-04-17  6:55 ` Kirill Yukhin
  2020-04-17 11:36   ` Roman Khabibov
  2020-05-08  7:20 ` Kirill Yukhin
  2 siblings, 1 reply; 7+ messages in thread
From: Kirill Yukhin @ 2020-04-17  6:55 UTC (permalink / raw)
  To: Roman Khabibov; +Cc: tarantool-patches

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
  2020-04-17  6:55 ` Kirill Yukhin
@ 2020-04-17 11:36   ` Roman Khabibov
  0 siblings, 0 replies; 7+ messages in thread
From: Roman Khabibov @ 2020-04-17 11:36 UTC (permalink / raw)
  To: Kirill Yukhin; +Cc: tarantool-patches

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)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Tarantool-patches] [PATCH] console: check on_shutdown() before exit
  2020-04-11 23:10 [Tarantool-patches] [PATCH] console: check on_shutdown() before exit Roman Khabibov
  2020-04-12 10:37 ` Cyrill Gorcunov
  2020-04-17  6:55 ` Kirill Yukhin
@ 2020-05-08  7:20 ` Kirill Yukhin
  2 siblings, 0 replies; 7+ messages in thread
From: Kirill Yukhin @ 2020-05-08  7:20 UTC (permalink / raw)
  To: Roman Khabibov; +Cc: tarantool-patches

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

LGTM.

I've checked your patch into 2.3, 2.4 and master.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-05-08  7:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-11 23:10 [Tarantool-patches] [PATCH] console: check on_shutdown() before exit 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
2020-05-08  7:20 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox