LP #1581949: Querying GLOBAL_TEMPORARY_TABLES crashes if temp-table owning threads execute new queries
Description
Environment
Smart Checklist
Activity
lpjirasync January 21, 2018 at 3:18 AM
**Comment from Launchpad by: Arturas Moskvinas on: 31-05-2016 06:12:04
Ok let see how it goes. Thanks!
lpjirasync January 21, 2018 at 3:18 AM
**Comment from Launchpad by: Laurynas Biveinis on: 31-05-2016 05:41:46
Never in my reproduction attempts I saw stacktraces resembling your case #1. I have added the equivalent of your reproduction script as a stress testcase to our codebase, and it hasn't crashed not once yet after fixing case #2.
Thus there's chance your case #1 is not fixed yet and we will iterate accordingly.
lpjirasync January 21, 2018 at 3:18 AM
**Comment from Launchpad by: Arturas Moskvinas on: 30-05-2016 15:14:52
Just wondering is both crashes are fixed by your fix?
lpjirasync January 21, 2018 at 3:18 AM
**Comment from Launchpad by: Laurynas Biveinis on: 30-05-2016 14:44:39
https://github.com/percona/percona-server/pull/543, https://github.com/percona/percona-server/pull/544, https://github.com/percona/percona-server/pull/545
lpjirasync January 21, 2018 at 3:17 AM
**Comment from Launchpad by: Laurynas Biveinis on: 24-05-2016 13:45:00
Valgrind on the same testcase
==19862== Thread 21:
==19862== Invalid write of size 8
==19862== at 0xBAAB01: ha_myisam::open(char const*, int, unsigned int) (ha_myisam.cc:748)
==19862== by 0x658CB9: handler::ha_open(TABLE*, char const*, int, int) (handler.cc:2744)
==19862== by 0x658840: handler::clone(char const*, st_mem_root*) (handler.cc:2658)
==19862== by 0xBAA966: ha_myisam::clone(char const*, st_mem_root*) (ha_myisam.cc:655)
==19862== by 0x86ECE2: store_temporary_table_record(THD*, TABLE*, TABLE*, char const*) (sql_show.cc:4175)
==19862== by 0x86F286: fill_global_temporary_tables(THD*, TABLE_LIST*, Item*) (sql_show.cc:4266)
==19862== by 0x87F61F: do_fill_table(THD*, TABLE_LIST*, st_join_table*) (sql_show.cc:8013)
==19862== by 0x87FA35: get_schema_tables_result(JOIN*, enum_schema_table_state) (sql_show.cc:8115)
==19862== by 0x84DC11: JOIN::prepare_result(List<Item>**) (sql_select.cc:823)
==19862== by 0x7E335B: JOIN::exec() (sql_executor.cc:116)
==19862== by 0x84E879: mysql_execute_select(THD*, st_select_lex*, bool) (sql_select.cc:1101)
==19862== by 0x84EBB4: mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, SQL_I_List<st_order>, SQL_I_List<st_order>, Item*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:1222)
==19862== by 0x84C884: handle_select(THD*, select_result*, unsigned long) (sql_select.cc:110)
==19862== by 0x8204D3: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5683)
==19862== by 0x81854F: mysql_execute_command(THD*) (sql_parse.cc:3005)
==19862== by 0x9F2397: sp_instr_stmt::exec_core(THD*, unsigned int*) (sp_instr.cc:953)
==19862== Address 0x15a40f58 is 1,064 bytes inside a block of size 1,168 free'd
==19862== at 0x4C2EDEB: free (vg_replace_malloc.c:530)
==19862== by 0xB2FED2: my_free (my_malloc.c:140)
==19862== by 0xB26C79: free_root (my_alloc.c:373)
==19862== by 0x815FC1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1899)
==19862== by 0x813710: do_command(THD*) (sql_parse.cc:1053)
==19862== by 0x7D6687: do_handle_one_connection(THD*) (sql_connect.cc:1541)
==19862== by 0x7D611F: handle_one_connection (sql_connect.cc:1444)
==19862== by 0xB989B2: pfs_spawn_thread (pfs.cc:1860)
==19862== by 0x5F656F9: start_thread (pthread_create.c:333)
==19862== by 0x6B22B5C: clone (clone.S:109)
==19862== Block was alloc'd at
==19862== at 0x4C2DB8F: malloc (vg_replace_malloc.c:299)
==19862== by 0xB2FA42: my_malloc (my_malloc.c:38)
==19862== by 0xB26357: alloc_root (my_alloc.c:173)
==19862== by 0x644476: Sql_alloc::operator new(unsigned long, st_mem_root*) (sql_alloc.h:40)
==19862== by 0xBA847B: myisam_create_handler(handlerton*, TABLE_SHARE*, st_mem_root*) (ha_myisam.cc:137)
==19862== by 0x653C56: get_new_handler(TABLE_SHARE*, st_mem_root*, handlerton*) (handler.cc:476)
==19862== by 0x65876E: handler::clone(char const*, st_mem_root*) (handler.cc:2636)
==19862== by 0xBAA966: ha_myisam::clone(char const*, st_mem_root*) (ha_myisam.cc:655)
==19862== by 0x86ECE2: store_temporary_table_record(THD*, TABLE*, TABLE*, char const*) (sql_show.cc:4175)
==19862== by 0x86F286: fill_global_temporary_tables(THD*, TABLE_LIST*, Item*) (sql_show.cc:4266)
==19862== by 0x87F61F: do_fill_table(THD*, TABLE_LIST*, st_join_table*) (sql_show.cc:8013)
==19862== by 0x87FA35: get_schema_tables_result(JOIN*, enum_schema_table_state) (sql_show.cc:8115)
==19862== by 0x84DC11: JOIN::prepare_result(List<Item>**) (sql_select.cc:823)
==19862== by 0x7E335B: JOIN::exec() (sql_executor.cc:116)
==19862== by 0x84E879: mysql_execute_select(THD*, st_select_lex*, bool) (sql_select.cc:1101)
==19862== by 0x84EBB4: mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, SQL_I_List<st_order>, SQL_I_List<st_order>, Item*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:1222)
Details
Details
Assignee
Reporter
Priority
Smart Checklist
Open Smart Checklist
Smart Checklist

**Reported in Launchpad by Arturas Moskvinas last update 31-05-2016 06:12:05
One of our production DB server was constantly crashing. Service is extensively using temporary tables in sessions and randomly server would crash if we were selecting information from GLOBAL_TEMPORARY_TABLES view.
Select:
SELECT engine, data_length, index_length FROM GLOBAL_TEMPORARY_TABLES;
How to reproduce issue:
1. In loop start selecting data from GLOBAL_TEMPORARY_TABLES
2. In second session - start creating lots of temporary tables
Simple script (sorry not mysql test suite):
1. In one session start such simple select (better reproducible if several sessions do the same):
watch -n 0.1 "mysql information_schema -e 'SELECT engine, data_length, index_length FROM GLOBAL_TEMPORARY_TABLES'"
2. In another session start creating lots of temporary tables (tested with 300, but usually mysql crashes faster, from time to time creation has to be repeated):
```
echo "Create temporary table a1(a varchar(256));Create temporary table a2(a varchar(256));Create temporary table a3(a varchar(256));Create temporary table a4(a varchar(256));Create temporary table a5(a varchar(256));Create temporary table a6(a varchar(256));Create temporary table a7(a varchar(256));Create temporary table a8(a varchar(256));Create temporary table a9(a varchar(256));Create temporary table a10(a varchar(256));Create temporary table a11(a varchar(256));Create temporary table a12(a varchar(256));Create temporary table a13(a varchar(256));Create temporary table a14(a varchar(256));Create temporary table a15(a varchar(256));Create temporary table a16(a varchar(256));Create temporary table a17(a varchar(256));Create temporary table a18(a varchar(256));Create temporary table a19(a varchar(256));Create temporary table a20(a varchar(256));Create temporary table a21(a varchar(256));Create temporary table a22(a varchar(256));Create temporary table a23(a varchar(256));Create temporary table a24(a varchar(256));Create temporary table a25(a varchar(256));Create temporary table a26(a varchar(256));...." | mysql test
```
Mysql error log:
```
11:29:47 UTC - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.
Please help us make Percona Server better by reporting any
bugs at http://bugs.percona.com/
key_buffer_size=16777216
read_buffer_size=131072
max_used_connections=11
max_threads=4098
thread_count=8
connection_count=6
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 1646765 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
Thread pointer: 0x7fec12b09000
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7fec690dae48 thread_stack 0x30000
/usr/sbin/mysqld(my_print_stacktrace+0x2c)[0x8ba78c]
/usr/sbin/mysqld(handle_fatal_signal+0x469)[0x646369]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf8d0)[0x7fec6b4a48d0]
/usr/sbin/mysqld(_Z21open_table_from_shareP3THDP11TABLE_SHAREPKcjjjP5TABLEb+0x3b2)[0x7464f2]
/usr/sbin/mysqld(_Z19open_table_uncachedP3THDPKcS2_S2_bb+0x188)[0x67ab18]
/usr/sbin/mysqld[0x7144b7]
/usr/sbin/mysqld(_Z26mysql_create_table_no_lockP3THDPKcS2_P24st_ha_create_informationP10Alter_infojPb+0xf8)[0x714ad8]
/usr/sbin/mysqld(_Z18mysql_create_tableP3THDP10TABLE_LISTP24st_ha_create_informationP10Alter_info+0xcc)[0x714c6c]
/usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x4f80)[0x6c8c50]
/usr/sbin/mysqld(_Z11mysql_parseP3THDPcjP12Parser_state+0x5d8)[0x6c9dd8]
/usr/sbin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x109b)[0x6cb52b]
/usr/sbin/mysqld(_Z24do_handle_one_connectionP3THD+0x1a2)[0x6981a2]
/usr/sbin/mysqld(handle_one_connection+0x40)[0x698240]
/usr/sbin/mysqld(pfs_spawn_thread+0x143)[0x8f5a83]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x80a4)[0x7fec6b49d0a4]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7fec6946f87d]
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (7febd541d010): is an invalid pointer
Connection ID (thread ID): 430
Status: NOT_KILLED
```
We also have core dump, stack trace from core dump is in attached file.
We also have core dump from original crash, stack trace is actually different and is caused by null reference during `SELECT engine, data_length, index_length FROM GLOBAL_TEMPORARY_TABLES` execution