[MDEV-16481] set global system_versioning_asof=sf() crashes in specific case Created: 2018-06-13  Updated: 2021-07-29  Resolved: 2021-07-28

Status: Closed
Project: MariaDB Server
Component/s: Stored routines, Versioned Tables
Affects Version/s: 10.3
Fix Version/s: 10.3.31, 10.4.21, 10.5.12, 10.6.4

Type: Bug Priority: Major
Reporter: Nikita Malyavin Assignee: Nikita Malyavin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
is blocked by MDEV-16026 Global system_versioning_asof must no... Closed

 Description   

If global variable is addressed inside a stored function, set global system_versioning_asof causes crash:

create or replace function NOW_GLOBAL() returns timestamp
  return  CONVERT_TZ(now(), @@session.time_zone, @@global.time_zone);
set global system_versioning_asof= NOW_GLOBAL();

safe_mutex: Trying to lock mutex at ../sql/item_func.cc, line 5668, when the mutex was already locked at ../sql/sys_vars_shared.h, line 55 in thread T@6
 
Thread pointer: 0x7f03f0000cf8
stack_bottom = 0x7f0406fc2dc8 thread_stack 0x49000
/home/foo/src/mariadb/bld/sql/mysqld(my_print_stacktrace+0x4f)[0x558095acc464]
mysys/stacktrace.c:269(my_print_stacktrace)[0x5580952d22c4]
sigaction.c:0(__restore_rt)[0x7f041408fb90]
:0(__GI_raise)[0x7f0411580efb]
:0(__GI_abort)[0x7f04115822c1]
/home/foo/src/mariadb/bld/sql/mysqld(safe_mutex_lock+0x149)[0x558095ad15dd]
mysys/thr_mutex.c:268(safe_mutex_lock)[0x558095353384]
psi/mysql_thread.h:695(inline_mysql_mutex_lock)[0x558095368008]
sql/item_func.cc:5669(Item_func_get_system_var::fix_length_and_dec())[0x55809535495a]
sql/item_func.cc:381(Item_func::fix_fields(THD*, Item**))[0x55809535478d]
sql/item_func.cc:363(Item_func::fix_fields(THD*, Item**))[0x558094ef7490]
sql/sp_head.cc:375(THD::sp_fix_func_item(Item**))[0x558094ef737b]
sql/sp_head.cc:362(THD::sp_prepare_func_item(Item**, unsigned int))[0x558095298603]
sql/field.cc:1330(Field::sp_prepare_and_store_item(THD*, Item**))[0x558094ef769e]
sql/sp_head.cc:411(THD::sp_eval_expr(Field*, Item**))[0x558094f0fbdb]
sql/sp_rcontext.cc:424(sp_rcontext::set_return_value(THD*, Item**))[0x558094f021c5]
sql/sp_head.cc:4014(sp_instr_freturn::exec_core(THD*, unsigned int*))[0x558094f00240]
sql/sp_head.cc:3317(sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*))[0x558094f020fa]
sql/sp_head.cc:3971(sp_instr_freturn::execute(THD*, unsigned int*))[0x558094efa4a4]
sql/sp_head.cc:1354(sp_head::execute(THD*, bool))[0x558094efc038]
sql/sp_head.cc:2011(sp_head::execute_function(THD*, Item**, unsigned int, Field*, sp_rcontext**, Query_arena*))[0x5580952f4912]
sql/item.cc:2956(Item_sp::execute_impl(THD*, Item**, unsigned int))[0x5580952f44ed]
sql/item.cc:2871(Item_sp::execute(THD*, bool*, Item**, unsigned int))[0x55809536a907]
sql/item_func.cc:6387(Item_func_sp::execute())[0x558095370c42]
sql/item_func.h:2873(Item_func_sp::get_date(st_mysql_time*, unsigned long long))[0x558095172f38]
sql/sys_vars.ic:2647(Sys_var_vers_asof::update(set_var*, vers_asof_timestamp_t&, system_variables&))[0x55809517301e]
sql/sys_vars.ic:2665(Sys_var_vers_asof::global_update(THD*, set_var*))[0x558094ed71aa]
sql/set_var.cc:208(sys_var::update(THD*, set_var*))[0x558094ed9088]
sql/set_var.cc:827(set_var::update(THD*))[0x558094ed8c53]
sql/set_var.cc:728(sql_set_variables(THD*, List<set_var_base>*, bool))[0x558094fdcfaa]
sql/sql_parse.cc:5136(mysql_execute_command(THD*))[0x558094fe6543]
sql/sql_parse.cc:8019(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x558094fd3443]
sql/sql_parse.cc:1848(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x558094fd1e4a]
sql/sql_parse.cc:1390(do_command(THD*))[0x55809513fd8e]
sql/sql_connect.cc:1402(do_handle_one_connection(CONNECT*))[0x55809513faf6]
sql/sql_connect.cc:1309(handle_one_connection)[0x558095a61508]
pthread_create.c:0(start_thread)[0x7f04140850bc]
:0(__GI___clone)[0x7f04116432ff]

This happenns because we access value->get_date() from update(), which locks global variables, because I used one in stored function, so we get double lock.



 Comments   
Comment by Sergei Golubchik [ 2020-10-19 ]

commit c308ce40ea844a368cc0a423e267bdf1b63096c0 is ok to push

Comment by Nikita Malyavin [ 2020-10-22 ]

will wait for the rest of the commits to be reviewed in the PR before pushing

Comment by Sergei Golubchik [ 2020-10-22 ]

sorry, not ok to push — see https://lists.launchpad.net/maria-developers/msg12439.html

Comment by Nikita Malyavin [ 2021-07-18 ]

The following commits are to review:
bfe08f36df339935a92a02ff98750f6ab9dffe47 (HEAD -> bb-10.3-nikita-old, origin/bb-10.3-nikita-old) add const qualifiers to sys_var::value_ptr functions and fix const casts
01ab3db8c739ecc14491fc602a19a5f9daf5b98b make all conversions in check() to avoid possible errors
a0631b06b725a072005cd91327ad30d246fa9f3b refactor Sys_var_vers_asof
19aebbd1b89feb1482e2cdf5ddb8322f48ad4216 MDEV-16481: set global system_versioning_asof=sf() crashes in specific case

Comment by Nikita Malyavin [ 2021-07-18 ]

see also
https://lists.launchpad.net/maria-developers/msg12419.html
https://lists.launchpad.net/maria-developers/msg12439.html

Comment by Sergei Golubchik [ 2021-07-19 ]

commits 19aebbd1b89fe..01ab3db8c73 are ok to push

bfe08f36df33 seems to be ok too, as far as I can see

Generated at Thu Feb 08 08:29:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.