Skip to content

Commit

Permalink
main: don't break graceful shutdown on init script exit
Browse files Browse the repository at this point in the history
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
nshy committed Nov 27, 2023
1 parent 24d7c8f commit c3c5eb2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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).
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

0 comments on commit c3c5eb2

Please sign in to comment.