forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: don't break graceful shutdown on init script exit
Graceful shutdown is done in a special fiber which is started for example on SIGTERM. So it can run concurrently with fiber executing Tarantool init script. On init fiber exit we break event loop to pass control back to the Tarantool initialization code. But we fail to run event loop a bit more to finish graceful shutdown. The test is a bit contrived. A more real world case is when Tarantool is termintated during lingering box.cfg(). Close tarantool#9411 NO_DOC=bugfix
- Loading branch information
Showing
3 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/unreleased/gh-9411-fix-graceful-shutdown-break-on-script-exit.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## bugfix/core | ||
|
||
* Fixed graceful shutdown break on init script exit (gh-9411). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/app-luatest/gh_9411_fix_graceful_shutdown_break_on_script_exit_test.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
local popen = require('popen') | ||
local t = require('luatest') | ||
|
||
local g = t.group() | ||
|
||
g.after_each(function() | ||
if g.handle ~= nil then | ||
g.handle:close() | ||
end | ||
g.handle = nil | ||
end) | ||
|
||
g.test = function() | ||
local script = [[ | ||
local fiber = require('fiber') | ||
box.ctl.set_on_shutdown_timeout(1) | ||
box.ctl.on_shutdown(function() | ||
fiber.sleep(0.2) | ||
print('shutdown callback finished') | ||
end, nil) | ||
fiber.create(function() | ||
os.exit(0) | ||
end) | ||
fiber.sleep(0.1) | ||
]] | ||
local tarantool_bin = arg[-1] | ||
local handle, err = popen.new({tarantool_bin, '-e', script}, | ||
{stdout = popen.opts.PIPE, | ||
stdin = popen.opts.DEVNULL, | ||
stderr = popen.opts.DEVNULL}) | ||
assert(handle, err) | ||
g.handle = handle | ||
local output, err = handle:read({timeout = 3}) | ||
assert(output, err) | ||
t.assert_equals(output, 'shutdown callback finished\n') | ||
local status = handle:wait() | ||
t.assert_equals(status.state, 'exited') | ||
t.assert_equals(status.exit_code, 0) | ||
end |