Skip to content

Commit b6ce68f

Browse files
committed
MDEV-13012 Assertion `share->error' failed in discover_handlerton upon executing statement with max_session_mem_used = 8192
and MDEV-13011 Server crashes in THD::handle_condition or Assertion `! is_set() || m_can_overwrite_status' fails upon attempt to connect with max_session_mem_used = 8192 errors when a connection is killed in the * TABLE_SHARE::init_from_sql_statement_string() * THD::init() also, safety-wise, don't check max_mem_used on free() and when some error was already issued.
1 parent d937916 commit b6ce68f

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

mysql-test/r/errors.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ UPDATE t1 SET a = 'new'
168168
WHERE COLUMN_CREATE( 1, 'v', 1, 'w' ) IS NULL;
169169
ERROR 22007: Illegal value used as argument of dynamic column function
170170
drop table t1;
171+
set max_session_mem_used = 8192;
172+
select * from seq_1_to_1000;
173+
ERROR HY000: Engine SEQUENCE failed to discover table `test`.`seq_1_to_1000` with 'create table seq (seq bigint unsigned primary key)'
174+
set global max_session_mem_used = default;

mysql-test/t/errors.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
22
# Test some error conditions
33
#
4+
--source include/have_sequence.inc
45

56
--disable_warnings
67
drop table if exists t1;
@@ -198,3 +199,11 @@ CREATE TABLE t1 (a CHAR(3), b BLOB);
198199
UPDATE t1 SET a = 'new'
199200
WHERE COLUMN_CREATE( 1, 'v', 1, 'w' ) IS NULL;
200201
drop table t1;
202+
203+
#
204+
# errors caused by max_session_mem_used
205+
#
206+
set max_session_mem_used = 8192;
207+
--error ER_SQL_DISCOVER_ERROR
208+
select * from seq_1_to_1000;
209+
set global max_session_mem_used = default;

sql/handler.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4857,7 +4857,12 @@ static my_bool discover_handlerton(THD *thd, plugin_ref plugin,
48574857
{
48584858
if (error)
48594859
{
4860-
DBUG_ASSERT(share->error); // tdc_lock_share needs that
4860+
if (!share->error)
4861+
{
4862+
share->error= OPEN_FRM_ERROR_ALREADY_ISSUED;
4863+
plugin_unlock(0, share->db_plugin);
4864+
}
4865+
48614866
/*
48624867
report an error, unless it is "generic" and a more
48634868
specific one was already reported

sql/mysqld.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3939,8 +3939,9 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
39393939
(longlong) thd->status_var.local_memory_used,
39403940
size));
39413941
thd->status_var.local_memory_used+= size;
3942-
if (thd->status_var.local_memory_used > (int64)thd->variables.max_mem_used &&
3943-
!thd->killed)
3942+
if (size > 0 &&
3943+
thd->status_var.local_memory_used > (int64)thd->variables.max_mem_used &&
3944+
!thd->killed && !thd->get_stmt_da()->is_set())
39443945
{
39453946
char buf[1024];
39463947
thd->killed= KILL_QUERY;
@@ -6646,11 +6647,12 @@ void handle_connections_sockets()
66466647
*/
66476648

66486649
DBUG_PRINT("info", ("Creating THD for new connection"));
6649-
if (!(thd= new THD))
6650+
if (!(thd= new THD) || thd->is_error())
66506651
{
66516652
(void) mysql_socket_shutdown(new_sock, SHUT_RDWR);
66526653
(void) mysql_socket_close(new_sock);
66536654
statistic_increment(connection_errors_internal, &LOCK_status);
6655+
delete thd;
66546656
continue;
66556657
}
66566658
/* Set to get io buffers to be part of THD */

sql/sql_class.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ THD::THD(bool is_wsrep_applier)
879879
debug_sync_control(0),
880880
#endif /* defined(ENABLED_DEBUG_SYNC) */
881881
wait_for_commit_ptr(0),
882+
m_internal_handler(0),
882883
main_da(0, false, false),
883884
m_stmt_da(&main_da),
884885
tdc_hash_pins(0),
@@ -1073,7 +1074,6 @@ THD::THD(bool is_wsrep_applier)
10731074
MYF(MY_WME|MY_THREAD_SPECIFIC));
10741075
}
10751076

1076-
m_internal_handler= NULL;
10771077
m_binlog_invoker= INVOKER_NONE;
10781078
memset(&invoker_user, 0, sizeof(invoker_user));
10791079
memset(&invoker_host, 0, sizeof(invoker_host));

0 commit comments

Comments
 (0)