Skip to content
Snippets Groups Projects
Commit 6bcabe27 authored by Oleg Babin's avatar Oleg Babin Committed by Vladimir Davydov
Browse files

box: fix crashes if some box.info functions called before box.cfg

Before this patch if one called `vinyl`, `sql`, `gc` and `memory`
functions from box.info() instance crashed. It's interesting that
`replication_anon` functions worked ok.
This patch fixes that crashes.

Closes #9173

NO_DOC=bugfix

(cherry picked from commit d85556c9)
parent 2757a847
No related branches found
No related tags found
No related merge requests found
## bugfix/box
* Fixed crashes if `box.info.memory()`, `box.info.gc()`, `box.info.vinyl()`,
and `box.info.sql()` are called before `box.cfg{}` (gh-9173).
......@@ -380,6 +380,9 @@ lbox_info_cluster(struct lua_State *L)
static int
lbox_info_memory_call(struct lua_State *L)
{
if (box_check_configured() != 0)
return luaT_error(L);
struct engine_memory_stat stat;
engine_memory_stat(&stat);
......@@ -432,6 +435,9 @@ lbox_info_memory(struct lua_State *L)
static int
lbox_info_gc_call(struct lua_State *L)
{
if (box_check_configured() != 0)
return luaT_error(L);
int count;
lua_newtable(L);
......@@ -530,6 +536,9 @@ lbox_info_gc(struct lua_State *L)
static int
lbox_info_vinyl_call(struct lua_State *L)
{
if (box_check_configured() != 0)
return luaT_error(L);
struct info_handler h;
luaT_info_handler_create(&h, L);
struct engine *vinyl = engine_by_name("vinyl");
......@@ -557,6 +566,9 @@ lbox_info_vinyl(struct lua_State *L)
static int
lbox_info_sql_call(struct lua_State *L)
{
if (box_check_configured() != 0)
return luaT_error(L);
struct info_handler h;
luaT_info_handler_create(&h, L);
sql_stmt_cache_stat(&h);
......
local t = require('luatest')
local g = t.group()
g.test_all_box_info = function()
-- Check that application won't be crashed
for _, func in pairs(box.info()) do
pcall(func)
end
end
g.test_box_info_errors = function()
t.assert_error_msg_equals('Please call box.cfg{} first',
box.info.memory)
t.assert_error_msg_equals('Please call box.cfg{} first',
box.info.sql)
t.assert_error_msg_equals('Please call box.cfg{} first',
box.info.vinyl)
t.assert_error_msg_equals('Please call box.cfg{} first',
box.info.gc)
t.assert_equals(box.info.replication_anon(), {},
'Works ok without box.cfg{}')
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment