diff --git a/src/main.cc b/src/main.cc index bb0794dfe6310068e69a14d2329a6d10a0ba14d3..a2cea3d40509532b0ca532466cbd16c057f9d255 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 0000000000000000000000000000000000000000..7c1aae2ba537f02ea2aff2792e4324363f8fc652 --- /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 0000000000000000000000000000000000000000..2b15277dbf412dce3d76441c87dc4dfe3cdab1b5 --- /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)