[MDEV-10034] Embedded server crashes on CREATE TABLE in PS protocol Created: 2016-05-06  Updated: 2016-05-08  Resolved: 2016-05-08

Status: Closed
Project: MariaDB Server
Component/s: Embedded Server, Prepared Statements
Affects Version/s: 10.1
Fix Version/s: 10.1.14

Type: Bug Priority: Blocker
Reporter: Elena Stepanova Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: regression

Issue Links:
Blocks
blocks MDEV-7069 Fix buildbot failures in main server ... Stalled

 Description   

# Run with --embedded --ps
 
CREATE TABLE t1 ( i INT );

Assertion failure on debug server:

Stack trace from 10.1 commit 1512078a7a56779d6fdd307a93187b61494de897

ysqltest_embedded: /src/10.1/libmysqld/../sql/mysqld.cc:4007: void my_malloc_size_cb_func(long long int, my_bool): Assertion `mysqld_server_initialized && thd' failed.
mysqltest got signal 6
 
#7  0x00007f38e11ae1d2 in __assert_fail () from /lib64/libc.so.6
#8  0x0000559daddb7719 in my_malloc_size_cb_func (size=2008, is_thread_specific=1 '\001') at /src/10.1/libmysqld/../sql/mysqld.cc:4007
#9  0x0000559dadd671f9 in update_malloc_size (size=2008, is_thread_specific=1 '\001') at /src/10.1/mysys/my_malloc.c:67
#10 0x0000559dadd67352 in my_malloc (size=2008, my_flags=69648) at /src/10.1/mysys/my_malloc.c:117
#11 0x0000559dadd6cd1e in alloc_root (mem_root=0x559db0bd8ee0, length=0) at /src/10.1/mysys/my_alloc.c:237
#12 0x0000559dadd842f4 in mysql_stmt_prepare (stmt=0x559db0bd8ee0, query=0x559db0bd8cc0 "CREATE TABLE t1 ( i INT )", length=25) at /src/10.1/libmysql/libmysql.c:1664
#13 0x0000559dadd34441 in connection_thread (arg=0x559db0a7a9d0) at /src/10.1/client/mysqltest.cc:886
#14 0x00007f38e2ea10a4 in start_thread () from /lib64/libpthread.so.0
#15 0x00007f38e126504d in clone () from /lib64/libc.so.6

Crash on non-debug server:

Stack trace from 10.1 commit 732adec0a4c75d99389230feeb0deca0ad668de7

#2  <signal handler called>
#3  my_malloc_size_cb_func (size=2016, is_thread_specific=<optimized out>) at /src/10.1-bug/libmysqld/../sql/mysqld.cc:4012
#4  0x000055ddbff9552d in update_malloc_size (is_thread_specific=1 '\001', size=2016) at /src/10.1-bug/mysys/my_malloc.c:67
#5  my_malloc (size=size@entry=2008, my_flags=69648) at /src/10.1-bug/mysys/my_malloc.c:117
#6  0x000055ddbff99212 in alloc_root (mem_root=mem_root@entry=0x55ddc1c31858, length=0) at /src/10.1-bug/mysys/my_alloc.c:237
#7  0x000055ddbffa0ac9 in mysql_stmt_prepare (stmt=0x55ddc1c31858, query=0x55ddc1c40308 "CREATE TABLE t1 ( i INT )", length=25) at /src/10.1-bug/libmysql/libmysql.c:1664
#8  0x000055ddbff67431 in connection_thread (arg=0x55ddc1b0e778) at /src/10.1-bug/client/mysqltest.cc:886
#9  0x00007f422b4cb0a4 in start_thread () from /lib64/libpthread.so.0
#10 0x00007f422988f04d in clone () from /lib64/libc.so.6

The problem was introduced by this commit:

commit b4ff64568c88ab3ce559e7bd39853d9cbf86704a
Author: Monty <monty@mariadb.org>
Date:   Thu Apr 28 11:10:55 2016 +0300
 
    Fixed wrong counting of global Memory_used



 Comments   
Comment by Oleksandr Byelkin [ 2016-05-06 ]

So the problem is that mem_root of prepared statement marked as thread specific.
Monty's patch bring strict check of THD on thread specific memory and mandatory usage of THD.

PS on embedded set THD too late.

#4 0x000055555599d952 in my_malloc_size_cb_func (size=2008, is_thread_specific=1 '\001') at /home/sanja/maria/git/server/libmysqld/../sql/mysqld.cc:4007
#5 0x000055555597d443 in update_malloc_size (size=2008, is_thread_specific=1 '\001') at /home/sanja/maria/git/server/mysys/my_malloc.c:67
#6 0x000055555597d59e in my_malloc (size=2008, my_flags=69648) at /home/sanja/maria/git/server/mysys/my_malloc.c:117
#7 0x000055555598292d in alloc_root (mem_root=0x5555576a6a90, length=0) at /home/sanja/maria/git/server/mysys/my_alloc.c:237
#8 0x0000555555995772 in mysql_stmt_prepare (stmt=0x5555576a6a90, query=0x5555575d9720 "CREATE TABLE t1 ( i INT )", length=25) at /home/sanja/maria/git/server/libmysql/libmysql.c:1664
#9 0x000055555594731a in connection_thread (arg=0x555557546980) at /home/sanja/maria/git/server/client/mysqltest.cc:885

IMHO THD should be set for all SP execution.

Other solution is return checking THD in my_malloc_size_cb_func.

Comment by Oleksandr Byelkin [ 2016-05-06 ]

There fix for the problem, but loaddata still fail (not all thread memory is free) and delete_returning (fields_mem_root marked as thread specific which I find wrong).

revision-id: 9002b9696fb6d35ffb6a23f318e4c221674e6cd2 (mariadb-10.1.13-41-g9002b96)
parent(s): 1512078a7a56779d6fdd307a93187b61494de897
committer: Oleksandr Byelkin
timestamp: 2016-05-06 15:42:40 +0200
message:

MDEV-10034: Embedded server crashes on CREATE TABLE in PS protocol

alloc_root & free_root require current THD in case if they marked as thread specific (and stmt does).

Generated at Thu Feb 08 07:39:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.