From f5e4e15403a4aaad67eb5ec1755798d2b9e08f9f Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 13 Sep 2022 11:46:28 +0900 Subject: [PATCH] Backport fix for MDEV-29352 to 10.3-10.5 The fix for MDEV-29352 was pushed to 10.6+ but the code causing the bug is old and the bug is unlikely to be a recent regression in 10.6. So, we apply the fix also to older versions, 10.3-10.5. The original commit message: MDEV-29352 SIGSEGV's in strlen and unknown location on optimized builds at SHUTDOWN When the UDF creation frails to write the newly created UDF into the related system table, the UDF is still created in memory. However, as it is now, the related DLL is unloaded in this case right in the mysql_create_function. And failure happens when the UDF handle is freed and tries to unload the respective DLL which is still unloaded. --- sql/sql_udf.cc | 5 +++-- .../spider/bugfix/include/restart_spider.inc | 8 ++++++++ .../mysql-test/spider/bugfix/r/mdev_29352.result | 12 ++++++++++++ .../mysql-test/spider/bugfix/t/mdev_29352.test | 11 +++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index d0657cf973e..86423c64f3f 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -606,7 +606,7 @@ int mysql_create_function(THD *thd,udf_func *udf) /* Allow creation of functions even if we can't open func table */ if (unlikely(!table)) - goto err; + goto err_open_func_table; table->use_all_columns(); restore_record(table, s->default_values); // Default values for fields table->field[0]->store(u_d->name.str, u_d->name.length, system_charset_info); @@ -620,7 +620,7 @@ int mysql_create_function(THD *thd,udf_func *udf) { my_error(ER_ERROR_ON_WRITE, MYF(0), "mysql.func", error); del_udf(u_d); - goto err; + goto err_open_func_table; } done: @@ -635,6 +635,7 @@ done: err: if (new_dl) dlclose(dl); +err_open_func_table: mysql_rwlock_unlock(&THR_LOCK_udf); DBUG_RETURN(1); } diff --git a/storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc b/storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc new file mode 100644 index 00000000000..a5446a6188d --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/restart_spider.inc @@ -0,0 +1,8 @@ +--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.1.1.expect + +--exec echo "wait" > $_expect_file_name +--shutdown_server +--source include/wait_until_disconnected.inc +--exec echo "restart" > $_expect_file_name +--enable_reconnect +--source include/wait_until_connected_again.inc diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result new file mode 100644 index 00000000000..5715edf2bd6 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_29352.result @@ -0,0 +1,12 @@ +CREATE TABLE t (c INT); +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `c` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +FLUSH TABLES WITH READ LOCK; +CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; +ERROR HY000: Can't execute the query because you have a conflicting read lock +SELECT * FROM t; +c +DROP TABLE t; diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test new file mode 100644 index 00000000000..00d8ee73ebc --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_29352.test @@ -0,0 +1,11 @@ +CREATE TABLE t (c INT); +SHOW CREATE TABLE t; +FLUSH TABLES WITH READ LOCK; + +--error ER_CANT_UPDATE_WITH_READLOCK +CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so'; +SELECT * FROM t; + +--source include/restart_spider.inc + +DROP TABLE t;