* [tarantool-patches] [PATCH] tarantoolctl: remove metatable assumptions in start() @ 2019-03-27 13:40 Roman Khabibov 2019-03-28 8:59 ` [tarantool-patches] " Konstantin Osipov ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Roman Khabibov @ 2019-03-27 13:40 UTC (permalink / raw) To: tarantool-patches; +Cc: alexander.turenko box.cfg{} metatables are uninitialized when start() called before box.cfg{}. It led to unexpected error. Closes #3953 --- Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3953-tctl Issue: https://github.com/tarantool/tarantool/issues/3953 extra/dist/tarantoolctl.in | 7 ------- test/app-tap/tarantoolctl.test.lua | 4 +++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 47fcf895f..91747e3ba 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -547,13 +547,6 @@ local function start() end os.exit(1) end - local old_call = getmetatable(box.cfg).__call - getmetatable(box.cfg).__call = function(old_cfg, cfg) - if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then - cfg.pid_file = old_cfg.pid_file - end - old_call(old_cfg, cfg) - end return 0 end diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index db046e03f..1755fcc66 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -165,10 +165,12 @@ do local dir = fio.tempdir() local code = [[ box.cfg{memtx_memory = 104857600} ]] create_script(dir, 'script.lua', code) + create_script(dir, 'init.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'init.lua', 0, nil, "Starting instance init...") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") -- 2.20.1 (Apple Git-117) ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-03-27 13:40 [tarantool-patches] [PATCH] tarantoolctl: remove metatable assumptions in start() Roman Khabibov @ 2019-03-28 8:59 ` Konstantin Osipov 2019-04-01 5:43 ` Alexander Turenko 2019-04-16 12:01 ` Kirill Yukhin 2 siblings, 0 replies; 10+ messages in thread From: Konstantin Osipov @ 2019-03-28 8:59 UTC (permalink / raw) To: tarantool-patches; +Cc: alexander.turenko * Roman Khabibov <roman.habibov@tarantool.org> [19/03/27 16:45]: > box.cfg{} metatables are uninitialized when start() called > before box.cfg{}. It led to unexpected error. I don't understand this fix and how it closes the bug. Could you please explain? AFAICS the test case in the bug declares a local variable 'cfg'. How does this conflict with box.cfg metatables? -- Konstantin Osipov, Moscow, Russia, +7 903 626 22 32 http://tarantool.io - www.twitter.com/kostja_osipov ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-03-27 13:40 [tarantool-patches] [PATCH] tarantoolctl: remove metatable assumptions in start() Roman Khabibov 2019-03-28 8:59 ` [tarantool-patches] " Konstantin Osipov @ 2019-04-01 5:43 ` Alexander Turenko 2019-04-05 23:26 ` Roman Khabibov 2019-04-16 12:01 ` Kirill Yukhin 2 siblings, 1 reply; 10+ messages in thread From: Alexander Turenko @ 2019-04-01 5:43 UTC (permalink / raw) To: Roman Khabibov; +Cc: tarantool-patches Commented in the issue, cited here: > @opomuc @olegrok I don't know what are you trying to do here. It seems > you just try to start an instance w/o box.cfg() call inside. I don't > see a reason to support this case. However more meaningful error > message from tarantoolctl start in the case would helpful. > > Re config module errors: I don't know whether you use it correctly. If > so, file another issue to this module. > > https://github.com/tarantool/tarantool/issues/3953#issuecomment-478439448 I propose to consider this issue as a problem with an error message. WBR, Alexander Turenko. On Wed, Mar 27, 2019 at 04:40:14PM +0300, Roman Khabibov wrote: > box.cfg{} metatables are uninitialized when start() called > before box.cfg{}. It led to unexpected error. > > Closes #3953 > --- > Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3953-tctl > Issue: https://github.com/tarantool/tarantool/issues/3953 > > extra/dist/tarantoolctl.in | 7 ------- > test/app-tap/tarantoolctl.test.lua | 4 +++- > 2 files changed, 3 insertions(+), 8 deletions(-) > > diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in > index 47fcf895f..91747e3ba 100755 > --- a/extra/dist/tarantoolctl.in > +++ b/extra/dist/tarantoolctl.in > @@ -547,13 +547,6 @@ local function start() > end > os.exit(1) > end > - local old_call = getmetatable(box.cfg).__call > - getmetatable(box.cfg).__call = function(old_cfg, cfg) > - if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then > - cfg.pid_file = old_cfg.pid_file So if a user lean on that value (s)he now cannot? > - end > - old_call(old_cfg, cfg) So if a user set a metatable on box.cfg() with __call method, it will not more called? > - end > return 0 > end > > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index db046e03f..1755fcc66 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -165,10 +165,12 @@ do > local dir = fio.tempdir() > local code = [[ box.cfg{memtx_memory = 104857600} ]] > create_script(dir, 'script.lua', code) > + create_script(dir, 'init.lua', [[ print('Hi!') ]]) > > local status, err = pcall(function() > test:test("basic test", function(test_i) > - test_i:plan(16) > + test_i:plan(18) > + check_ok(test_i, dir, 'start', 'init.lua', 0, nil, "Starting instance init...") So we're 'successfully' started an instance, it executes a script and then 'tarantoolctl status' and 'tarantoolctl enter' don't show it as running. It does not look as a right behaviour. > check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") > tctl_wait_start(dir, 'script') > check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") > -- > 2.20.1 (Apple Git-117) > ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-04-01 5:43 ` Alexander Turenko @ 2019-04-05 23:26 ` Roman Khabibov 2019-04-11 14:57 ` Alexander Turenko 0 siblings, 1 reply; 10+ messages in thread From: Roman Khabibov @ 2019-04-05 23:26 UTC (permalink / raw) To: tarantool-patches; +Cc: Alexander Turenko Hello! Thanks for review. > On Apr 1, 2019, at 8:43 AM, Alexander Turenko <alexander.turenko@tarantool.org> wrote: > > Commented in the issue, cited here: > >> @opomuc @olegrok I don't know what are you trying to do here. It seems >> you just try to start an instance w/o box.cfg() call inside. I don't >> see a reason to support this case. However more meaningful error >> message from tarantoolctl start in the case would helpful. >> >> Re config module errors: I don't know whether you use it correctly. If >> so, file another issue to this module. >> >> https://github.com/tarantool/tarantool/issues/3953#issuecomment-478439448 > > I propose to consider this issue as a problem with an error message. > > WBR, Alexander Turenko. > > On Wed, Mar 27, 2019 at 04:40:14PM +0300, Roman Khabibov wrote: >> box.cfg{} metatables are uninitialized when start() called >> before box.cfg{}. It led to unexpected error. >> >> Closes #3953 >> --- >> Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3953-tctl >> Issue: https://github.com/tarantool/tarantool/issues/3953 >> >> extra/dist/tarantoolctl.in | 7 ------- >> test/app-tap/tarantoolctl.test.lua | 4 +++- >> 2 files changed, 3 insertions(+), 8 deletions(-) >> >> diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in >> index 47fcf895f..91747e3ba 100755 >> --- a/extra/dist/tarantoolctl.in >> +++ b/extra/dist/tarantoolctl.in >> @@ -547,13 +547,6 @@ local function start() >> end >> os.exit(1) >> end >> - local old_call = getmetatable(box.cfg).__call >> - getmetatable(box.cfg).__call = function(old_cfg, cfg) >> - if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then >> - cfg.pid_file = old_cfg.pid_file > > So if a user lean on that value (s)he now cannot? > >> - end >> - old_call(old_cfg, cfg) > > So if a user set a metatable on box.cfg() with __call method, it will > not more called? > >> - end >> return 0 >> end >> >> diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua >> index db046e03f..1755fcc66 100755 >> --- a/test/app-tap/tarantoolctl.test.lua >> +++ b/test/app-tap/tarantoolctl.test.lua >> @@ -165,10 +165,12 @@ do >> local dir = fio.tempdir() >> local code = [[ box.cfg{memtx_memory = 104857600} ]] >> create_script(dir, 'script.lua', code) >> + create_script(dir, 'init.lua', [[ print('Hi!') ]]) >> >> local status, err = pcall(function() >> test:test("basic test", function(test_i) >> - test_i:plan(16) >> + test_i:plan(18) >> + check_ok(test_i, dir, 'start', 'init.lua', 0, nil, "Starting instance init…") Reworked. + local m_table = getmetatable(box.cfg) + if m_table == nil then + error("Plaese, call box.cfg{} within your instance") + end + local old_call = m_table.__call > So we're 'successfully' started an instance, it executes a script and > then 'tarantoolctl status' and 'tarantoolctl enter' don't show it as > running. It does not look as a right behaviour. > >> check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") >> tctl_wait_start(dir, 'script') >> check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") >> -- >> 2.20.1 (Apple Git-117) check_ok(test_i, dir, 'status', 'script', 0, nil, "is running”) - I think it’s OK. Instance ’script’ have already been started, so ’tarantoolctl status script’ returns 0. commit 4cdf8e79bb530288098fb30e5014498fc0ad4262 Author: Roman Khabibov <roman.habibov@tarantool.org> Date: Mon Mar 25 20:52:05 2019 +0300 tarantoolctl: error when box.cfg didn't called There was assumpted uninitialized metamethods of box.cfg{} if user did't call it in his instance. Closes #3953 diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 47fcf895f..396fa7957 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -547,7 +547,11 @@ local function start() end os.exit(1) end - local old_call = getmetatable(box.cfg).__call + local m_table = getmetatable(box.cfg) + if m_table == nil then + error("Plaese, call box.cfg{} within your instance") + end + local old_call = m_table.__call getmetatable(box.cfg).__call = function(old_cfg, cfg) if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then cfg.pid_file = old_cfg.pid_file diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index db046e03f..428b074e2 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -165,10 +165,13 @@ do local dir = fio.tempdir() local code = [[ box.cfg{memtx_memory = 104857600} ]] create_script(dir, 'script.lua', code) + create_script(dir, 'init.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'init.lua', 1, nil, "Starting instance init...", + "Plaese, call box.cfg{} within your instance") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-04-05 23:26 ` Roman Khabibov @ 2019-04-11 14:57 ` Alexander Turenko 2019-04-12 9:29 ` Roman Khabibov 0 siblings, 1 reply; 10+ messages in thread From: Alexander Turenko @ 2019-04-11 14:57 UTC (permalink / raw) To: Roman Khabibov; +Cc: tarantool-patches The behaviour is almost okay, but you need to work on wording of the commit message to make it useful for a reader. Feel free to ask more if you have questions. See comments below. WBR, Alexander Turenko. > commit 4cdf8e79bb530288098fb30e5014498fc0ad4262 > Author: Roman Khabibov <roman.habibov@tarantool.org> > Date: Mon Mar 25 20:52:05 2019 +0300 > > tarantoolctl: error when box.cfg didn't called Cite from our developer guidelines [1]: > 6. Use the imperative mood in the subject line. A properly formed Git > commit subject line should always be able to complete the following > sentence: “If applied, this commit will /your subject line here/”. [1]: https://www.tarantool.io/en/doc/1.10/dev_guide/developer_guidelines/#how-to-write-a-commit-message Also you construct passive voice wrongly, it should be 'to be + [not] + Ved'. > > There was assumpted uninitialized metamethods of box.cfg{} if user > did't call it in his instance. This sentence raises more questions then give answers. What is 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of the call or a new value of the 'cfg' field of the 'box' table? Also I doubt 'There was assumpted' is valid phrase. > > Closes #3953 > > diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in > index 47fcf895f..396fa7957 100755 > --- a/extra/dist/tarantoolctl.in > +++ b/extra/dist/tarantoolctl.in > @@ -547,7 +547,11 @@ local function start() > end > os.exit(1) > end > - local old_call = getmetatable(box.cfg).__call > + local m_table = getmetatable(box.cfg) > + if m_table == nil then Cite from our Lua style guide [2]: > `*_mt` and `*_methods` defines metatable and methods table Suggested to name it box_cfg_mt. [2]: https://www.tarantool.io/en/doc/1.10/dev_guide/lua_style_guide/ > + error("Plaese, call box.cfg{} within your instance") Typo: 'Plaese'. I would change wording to just state what is wrong, e.g.: 'box.cfg() is not called in an instance file'. See also how errors are reported in other places: log.error() and os.exit(1). I guess it does not matter much from a behaviour point of view, but it would be good to report errors in one way with surrounding code. (BTW, found one behaviour difference: error() reports a line number when called with one argument or non-zero second argument.) Please, install tarantool and tarantoolctl and check the behaviour: messages and exit codes. Currently it looks so: # tarantoolctl start foo Starting instance foo... Hello, World! /usr/bin/tarantoolctl:552: Plaese, call box.cfg{} within your instance # echo $? 1 It is okay except file:line part, but anyway I suggest you to use log.error() and os.exit(1). > + end > + local old_call = m_table.__call > getmetatable(box.cfg).__call = function(old_cfg, cfg) There is no need to call getmetatable() again, we can use box_cfg_mt. > if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then > cfg.pid_file = old_cfg.pid_file > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index db046e03f..428b074e2 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -165,10 +165,13 @@ do > local dir = fio.tempdir() > local code = [[ box.cfg{memtx_memory = 104857600} ]] > create_script(dir, 'script.lua', code) > + create_script(dir, 'init.lua', [[ print('Hi!') ]]) > > local status, err = pcall(function() > test:test("basic test", function(test_i) > - test_i:plan(16) > + test_i:plan(18) > + check_ok(test_i, dir, 'start', 'init.lua', 1, nil, "Starting instance init...", > + "Plaese, call box.cfg{} within your instance") > check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") > tctl_wait_start(dir, 'script') > check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") > > I propose to make the code of the test a bit more uniform and use a meaningful instance file name: diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 428b074e2..7d7c63371 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -163,15 +163,14 @@ test:plan(7) -- must be stopped afterwards do local dir = fio.tempdir() - local code = [[ box.cfg{memtx_memory = 104857600} ]] - create_script(dir, 'script.lua', code) - create_script(dir, 'init.lua', [[ print('Hi!') ]]) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) test_i:plan(18) - check_ok(test_i, dir, 'start', 'init.lua', 1, nil, "Starting instance init...", - "Plaese, call box.cfg{} within your instance") + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", + "box.cfg() is not called in an instance file") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-04-11 14:57 ` Alexander Turenko @ 2019-04-12 9:29 ` Roman Khabibov 2019-04-14 22:41 ` Alexander Turenko 0 siblings, 1 reply; 10+ messages in thread From: Roman Khabibov @ 2019-04-12 9:29 UTC (permalink / raw) To: tarantool-patches; +Cc: Alexander Turenko Hi! Thanks for the review. > On Apr 11, 2019, at 5:57 PM, Alexander Turenko <alexander.turenko@tarantool.org> wrote: > > The behaviour is almost okay, but you need to work on wording of the > commit message to make it useful for a reader. Feel free to ask more if > you have questions. > > See comments below. > > WBR, Alexander Turenko. > >> commit 4cdf8e79bb530288098fb30e5014498fc0ad4262 >> Author: Roman Khabibov <roman.habibov@tarantool.org> >> Date: Mon Mar 25 20:52:05 2019 +0300 >> >> tarantoolctl: error when box.cfg didn't called > > Cite from our developer guidelines [1]: > >> 6. Use the imperative mood in the subject line. A properly formed Git >> commit subject line should always be able to complete the following >> sentence: “If applied, this commit will /your subject line here/”. > > [1]: https://www.tarantool.io/en/doc/1.10/dev_guide/developer_guidelines/#how-to-write-a-commit-message > > Also you construct passive voice wrongly, it should be 'to be + [not] + Ved'. > >> >> There was assumpted uninitialized metamethods of box.cfg{} if user >> did't call it in his instance. > > This sentence raises more questions then give answers. What is > 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of the > call or a new value of the 'cfg' field of the 'box' table? > > Also I doubt 'There was assumpted' is valid phrase. tarantoolctl: raise error when box.cfg isn't called There was no check whether box.cfg{} was initialized in an instance. If so, an error should be raised. >> >> Closes #3953 >> >> diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in >> index 47fcf895f..396fa7957 100755 >> --- a/extra/dist/tarantoolctl.in >> +++ b/extra/dist/tarantoolctl.in >> @@ -547,7 +547,11 @@ local function start() >> end >> os.exit(1) >> end >> - local old_call = getmetatable(box.cfg).__call >> + local m_table = getmetatable(box.cfg) >> + if m_table == nil then > > Cite from our Lua style guide [2]: > >> `*_mt` and `*_methods` defines metatable and methods table > > Suggested to name it box_cfg_mt. + local box_cfg_mt = getmetatable(box.cfg) > [2]: https://www.tarantool.io/en/doc/1.10/dev_guide/lua_style_guide/ > >> + error("Plaese, call box.cfg{} within your instance") > > Typo: 'Plaese'. > > I would change wording to just state what is wrong, e.g.: 'box.cfg() is > not called in an instance file'. > > See also how errors are reported in other places: log.error() and > os.exit(1). I guess it does not matter much from a behaviour point of > view, but it would be good to report errors in one way with surrounding > code. > > (BTW, found one behaviour difference: error() reports a line number when > called with one argument or non-zero second argument.) > > Please, install tarantool and tarantoolctl and check the behaviour: > messages and exit codes. Currently it looks so: > > # tarantoolctl start foo > Starting instance foo... > Hello, World! > /usr/bin/tarantoolctl:552: Plaese, call box.cfg{} within your instance > # echo $? > 1 > > It is okay except file:line part, but anyway I suggest you to use > log.error() and os.exit(1). + if box_cfg_mt == nil then + log.error('box.cfg() is not called in an instance file') + os.exit(1) > >> if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then >> cfg.pid_file = old_cfg.pid_file >> diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua >> index db046e03f..428b074e2 100755 >> --- a/test/app-tap/tarantoolctl.test.lua >> +++ b/test/app-tap/tarantoolctl.test.lua >> @@ -165,10 +165,13 @@ do >> local dir = fio.tempdir() >> local code = [[ box.cfg{memtx_memory = 104857600} ]] >> create_script(dir, 'script.lua', code) >> + create_script(dir, 'init.lua', [[ print('Hi!') ]]) >> >> local status, err = pcall(function() >> test:test("basic test", function(test_i) >> - test_i:plan(16) >> + test_i:plan(18) >> + check_ok(test_i, dir, 'start', 'init.lua', 1, nil, "Starting instance init...", >> + "Plaese, call box.cfg{} within your instance") >> check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") >> tctl_wait_start(dir, 'script') >> check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") >> >> > > I propose to make the code of the test a bit more uniform and use a > meaningful instance file name: > > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index 428b074e2..7d7c63371 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -163,15 +163,14 @@ test:plan(7) > -- must be stopped afterwards > do > local dir = fio.tempdir() > - local code = [[ box.cfg{memtx_memory = 104857600} ]] > - create_script(dir, 'script.lua', code) > - create_script(dir, 'init.lua', [[ print('Hi!') ]]) > + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) > + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) > > local status, err = pcall(function() > test:test("basic test", function(test_i) > test_i:plan(18) > - check_ok(test_i, dir, 'start', 'init.lua', 1, nil, "Starting instance init...", > - "Plaese, call box.cfg{} within your instance") > + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", > + "box.cfg() is not called in an instance file") > check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") > tctl_wait_start(dir, 'script') > check_ok(test_i, dir, 'status', 'script', 0, nil, "is running”) - local code = [[ box.cfg{memtx_memory = 104857600} ]] - create_script(dir, 'script.lua', code) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", + "box.cfg() is not called in an instance file”) commit 834545cc83965f6d612fcccd39dda03074e7f227 Author: Roman Khabibov <roman.habibov@tarantool.org> Date: Mon Mar 25 20:52:05 2019 +0300 tarantoolctl: raise error when box.cfg isn't called There was no check whether box.cfg{} was initialized in an instance. If so, an error should be raised. Closes #3953 diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 47fcf895f..37ded5333 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -547,8 +547,13 @@ local function start() end os.exit(1) end - local old_call = getmetatable(box.cfg).__call - getmetatable(box.cfg).__call = function(old_cfg, cfg) + local box_cfg_mt = getmetatable(box.cfg) + if box_cfg_mt == nil then + log.error('box.cfg() is not called in an instance file') + os.exit(1) + end + local old_call = box_cfg_mt.__call + box_cfg_mt.__call = function(old_cfg, cfg) if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then cfg.pid_file = old_cfg.pid_file end diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index db046e03f..7d7c63371 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -163,12 +163,14 @@ test:plan(7) -- must be stopped afterwards do local dir = fio.tempdir() - local code = [[ box.cfg{memtx_memory = 104857600} ]] - create_script(dir, 'script.lua', code) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", + "box.cfg() is not called in an instance file") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-04-12 9:29 ` Roman Khabibov @ 2019-04-14 22:41 ` Alexander Turenko 2019-04-15 10:59 ` Roman Khabibov 0 siblings, 1 reply; 10+ messages in thread From: Alexander Turenko @ 2019-04-14 22:41 UTC (permalink / raw) To: Roman Khabibov; +Cc: tarantool-patches The code is okay, but I would clarify the commit message a bit. > >> > >> There was assumpted uninitialized metamethods of box.cfg{} if user > >> did't call it in his instance. > > > > This sentence raises more questions then give answers. What is > > 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of the > > call or a new value of the 'cfg' field of the 'box' table? > > > > Also I doubt 'There was assumpted' is valid phrase. > > tarantoolctl: raise error when box.cfg isn't called > > There was no check whether box.cfg{} was initialized in an > instance. If so, an error should be raised. 'box' can be initialized (it is a module), 'box.cfg' can be called, but we usually use parentheses to mark a name as a function, so 'box.cfg()' can be called. Technically 'box.cfg{} was initialized' is not correct. 'If so' here point to the positive case (when called). Let me propose wording that will satisfy me: > Added a check whether box.cfg() is called within an instance file. If > box.cfg() is missed, point a user the reason of a fail explicitly. > > Before this commit the error was look so: > > /usr/bin/tarantoolctl:541: attempt to index a nil value Also don't forget to add 'Fixes #xxxx' clause to the end of the commit message. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-04-14 22:41 ` Alexander Turenko @ 2019-04-15 10:59 ` Roman Khabibov 2019-04-15 12:55 ` Alexander Turenko 0 siblings, 1 reply; 10+ messages in thread From: Roman Khabibov @ 2019-04-15 10:59 UTC (permalink / raw) To: tarantool-patches; +Cc: Alexander Turenko > On Apr 15, 2019, at 1:41 AM, Alexander Turenko <alexander.turenko@tarantool.org> wrote: > > The code is okay, but I would clarify the commit message a bit. > >>>> >>>> There was assumpted uninitialized metamethods of box.cfg{} if user >>>> did't call it in his instance. >>> >>> This sentence raises more questions then give answers. What is >>> 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of the >>> call or a new value of the 'cfg' field of the 'box' table? >>> >>> Also I doubt 'There was assumpted' is valid phrase. >> >> tarantoolctl: raise error when box.cfg isn't called >> >> There was no check whether box.cfg{} was initialized in an >> instance. If so, an error should be raised. > > 'box' can be initialized (it is a module), 'box.cfg' can be called, but > we usually use parentheses to mark a name as a function, so 'box.cfg()' > can be called. Technically 'box.cfg{} was initialized' is not correct. > > 'If so' here point to the positive case (when called). > > Let me propose wording that will satisfy me: > >> Added a check whether box.cfg() is called within an instance file. If >> box.cfg() is missed, point a user the reason of a fail explicitly. >> >> Before this commit the error was look so: >> >> /usr/bin/tarantoolctl:541: attempt to index a nil value > > Also don't forget to add 'Fixes #xxxx' clause to the end of the commit > message. Done. commit 7aba9a68b1139738fc3da1bfa39c490f3afdfc5e Author: Roman Khabibov <roman.habibov@tarantool.org> Date: Mon Mar 25 20:52:05 2019 +0300 tarantoolctl: raise error when box.cfg isn't called Added a check whether box.cfg() is called within an instance file. If box.cfg() is missed, point a user the reason of a fail explicitly. Before this commit the error was look so: /usr/bin/tarantoolctl:541: attempt to index a nil value Closes #3953 diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 47fcf895f..37ded5333 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -547,8 +547,13 @@ local function start() end os.exit(1) end - local old_call = getmetatable(box.cfg).__call - getmetatable(box.cfg).__call = function(old_cfg, cfg) + local box_cfg_mt = getmetatable(box.cfg) + if box_cfg_mt == nil then + log.error('box.cfg() is not called in an instance file') + os.exit(1) + end + local old_call = box_cfg_mt.__call + box_cfg_mt.__call = function(old_cfg, cfg) if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then cfg.pid_file = old_cfg.pid_file end diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index db046e03f..7d7c63371 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -163,12 +163,14 @@ test:plan(7) -- must be stopped afterwards do local dir = fio.tempdir() - local code = [[ box.cfg{memtx_memory = 104857600} ]] - create_script(dir, 'script.lua', code) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) local status, err = pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", + "box.cfg() is not called in an instance file") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-04-15 10:59 ` Roman Khabibov @ 2019-04-15 12:55 ` Alexander Turenko 0 siblings, 0 replies; 10+ messages in thread From: Alexander Turenko @ 2019-04-15 12:55 UTC (permalink / raw) To: Roman Khabibov; +Cc: tarantool-patches, Kirill Yukhin LGTM. Kirill, please, proceed. https://github.com/tarantool/tarantool/issues/3953 https://github.com/tarantool/tarantool/compare/romanhabibov/gh-3953-tctl WBR, Alexander Turenko. On Mon, Apr 15, 2019 at 01:59:31PM +0300, Roman Khabibov wrote: > > > > On Apr 15, 2019, at 1:41 AM, Alexander Turenko <alexander.turenko@tarantool.org> wrote: > > > > The code is okay, but I would clarify the commit message a bit. > > > >>>> > >>>> There was assumpted uninitialized metamethods of box.cfg{} if user > >>>> did't call it in his instance. > >>> > >>> This sentence raises more questions then give answers. What is > >>> 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of the > >>> call or a new value of the 'cfg' field of the 'box' table? > >>> > >>> Also I doubt 'There was assumpted' is valid phrase. > >> > >> tarantoolctl: raise error when box.cfg isn't called > >> > >> There was no check whether box.cfg{} was initialized in an > >> instance. If so, an error should be raised. > > > > 'box' can be initialized (it is a module), 'box.cfg' can be called, but > > we usually use parentheses to mark a name as a function, so 'box.cfg()' > > can be called. Technically 'box.cfg{} was initialized' is not correct. > > > > 'If so' here point to the positive case (when called). > > > > Let me propose wording that will satisfy me: > > > >> Added a check whether box.cfg() is called within an instance file. If > >> box.cfg() is missed, point a user the reason of a fail explicitly. > >> > >> Before this commit the error was look so: > >> > >> /usr/bin/tarantoolctl:541: attempt to index a nil value > > > > Also don't forget to add 'Fixes #xxxx' clause to the end of the commit > > message. > Done. > > commit 7aba9a68b1139738fc3da1bfa39c490f3afdfc5e > Author: Roman Khabibov <roman.habibov@tarantool.org> > Date: Mon Mar 25 20:52:05 2019 +0300 > > tarantoolctl: raise error when box.cfg isn't called > > Added a check whether box.cfg() is called within an instance > file. If box.cfg() is missed, point a user the reason of a > fail explicitly. > > Before this commit the error was look so: > > /usr/bin/tarantoolctl:541: attempt to index a nil value > > Closes #3953 > > diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in > index 47fcf895f..37ded5333 100755 > --- a/extra/dist/tarantoolctl.in > +++ b/extra/dist/tarantoolctl.in > @@ -547,8 +547,13 @@ local function start() > end > os.exit(1) > end > - local old_call = getmetatable(box.cfg).__call > - getmetatable(box.cfg).__call = function(old_cfg, cfg) > + local box_cfg_mt = getmetatable(box.cfg) > + if box_cfg_mt == nil then > + log.error('box.cfg() is not called in an instance file') > + os.exit(1) > + end > + local old_call = box_cfg_mt.__call > + box_cfg_mt.__call = function(old_cfg, cfg) > if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then > cfg.pid_file = old_cfg.pid_file > end > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index db046e03f..7d7c63371 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -163,12 +163,14 @@ test:plan(7) > -- must be stopped afterwards > do > local dir = fio.tempdir() > - local code = [[ box.cfg{memtx_memory = 104857600} ]] > - create_script(dir, 'script.lua', code) > + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) > + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) > > local status, err = pcall(function() > test:test("basic test", function(test_i) > - test_i:plan(16) > + test_i:plan(18) > + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", > + "box.cfg() is not called in an instance file") > check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") > tctl_wait_start(dir, 'script') > check_ok(test_i, dir, 'status', 'script', 0, nil, "is running") ^ permalink raw reply [flat|nested] 10+ messages in thread
* [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() 2019-03-27 13:40 [tarantool-patches] [PATCH] tarantoolctl: remove metatable assumptions in start() Roman Khabibov 2019-03-28 8:59 ` [tarantool-patches] " Konstantin Osipov 2019-04-01 5:43 ` Alexander Turenko @ 2019-04-16 12:01 ` Kirill Yukhin 2 siblings, 0 replies; 10+ messages in thread From: Kirill Yukhin @ 2019-04-16 12:01 UTC (permalink / raw) To: tarantool-patches; +Cc: alexander.turenko Hello, On 27 мар 16:40, Roman Khabibov wrote: > box.cfg{} metatables are uninitialized when start() called > before box.cfg{}. It led to unexpected error. > > Closes #3953 > --- > Branch: https://github.com/tarantool/tarantool/tree/romanhabibov/gh-3953-tctl > Issue: https://github.com/tarantool/tarantool/issues/3953 I've checked your patch into 1.10, 2.1 and master branches. -- Regards, Kirill Yukhin ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2019-04-16 12:01 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-03-27 13:40 [tarantool-patches] [PATCH] tarantoolctl: remove metatable assumptions in start() Roman Khabibov 2019-03-28 8:59 ` [tarantool-patches] " Konstantin Osipov 2019-04-01 5:43 ` Alexander Turenko 2019-04-05 23:26 ` Roman Khabibov 2019-04-11 14:57 ` Alexander Turenko 2019-04-12 9:29 ` Roman Khabibov 2019-04-14 22:41 ` Alexander Turenko 2019-04-15 10:59 ` Roman Khabibov 2019-04-15 12:55 ` Alexander Turenko 2019-04-16 12:01 ` Kirill Yukhin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox