Bug #86620 Assertion `__null != dynamic_cast<Target>(arg)' failure
Submitted: 8 Jun 2017 10:22 Modified: 2 Aug 2017 7:37
Reporter: Parveez Baig Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: JSON Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[8 Jun 2017 10:22] Parveez Baig
Description:
If data inserted to the json column contains json array as value for two keys and if both the keys are same, then the insert will result in below assertion failure.

mysqld: /home/parveez/code/mysql/include/template_utils.h:86: Target down_cast(Source) [with Target = Json_array*; Source = Json_dom*]: Assertion `__null != dynamic_cast<Target>(arg)' failed.
10:05:18 UTC - mysqld got signal 6 ;
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.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=1
connection_count=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68202 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x7fc4a8000be0
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 = 7fc5280c9d40 thread_stack 0x46000
/home/parveez/code/mysql/sql/mysqld(my_print_stacktrace+0x46) [0x295b41f]
/home/parveez/code/mysql/sql/mysqld(handle_fatal_signal+0x3f5) [0x1fccd2a]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7fc532c40340]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x39) [0x7fc531a3ccc9]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x148) [0x7fc531a400d8]
/lib/x86_64-linux-gnu/libc.so.6(+0x2fb86) [0x7fc531a35b86]
/lib/x86_64-linux-gnu/libc.so.6(+0x2fc32) [0x7fc531a35c32]
/home/parveez/code/mysql/sql/mysqld(Json_array* down_cast<Json_array*, Json_dom*>(Json_dom*)+0x54) [0x22016a1]
/home/parveez/code/mysql/sql/mysqld() [0x2260d5e]
/home/parveez/code/mysql/sql/mysqld() [0x22611a0]
/home/parveez/code/mysql/sql/mysqld() [0x226da2e]
/home/parveez/code/mysql/sql/mysqld() [0x226b342]
/home/parveez/code/mysql/sql/mysqld() [0x226e1c8]
/home/parveez/code/mysql/sql/mysqld() [0x226b374]
/home/parveez/code/mysql/sql/mysqld() [0x226de32]
/home/parveez/code/mysql/sql/mysqld() [0x226b35b]
/home/parveez/code/mysql/sql/mysqld() [0x226aaed]
/home/parveez/code/mysql/sql/mysqld(Json_dom::parse(char const*, unsigned long, char const**, unsigned long*, bool)+0xc4) [0x2261648]
/home/parveez/code/mysql/sql/mysqld(Field_json::store(char const*, unsigned long, charset_info_st const*)+0x106) [0x20d54c6]
/home/parveez/code/mysql/sql/mysqld(Item::save_str_value_in_field(Field*, String*)+0x8a) [0x2148810]
/home/parveez/code/mysql/sql/mysqld(Item_string::save_in_field_inner(Field*, bool)+0x54) [0x215b350]
/home/parveez/code/mysql/sql/mysqld(Item::save_in_field(Field*, bool)+0x34) [0x215a876]
/home/parveez/code/mysql/sql/mysqld(fill_record(THD*, TABLE*, Field**, List<Item>&, st_bitmap*, st_bitmap*)+0x182) [0x1bda857]
/home/parveez/code/mysql/sql/mysqld(fill_record_n_invoke_before_triggers(THD*, Field**, List<Item>&, TABLE*, enum_trigger_event_type, int)+0x1ae) [0x1bdab47]
/home/parveez/code/mysql/sql/mysqld(Sql_cmd_insert_values::execute_inner(THD*)+0x97d) [0x23222ed]
/home/parveez/code/mysql/sql/mysqld(Sql_cmd_dml::execute(THD*)+0x3b1) [0x1cc0679]
/home/parveez/code/mysql/sql/mysqld(mysql_execute_command(THD*, bool)+0x1fc7) [0x1c67446]
/home/parveez/code/mysql/sql/mysqld(mysql_parse(THD*, Parser_state*)+0x52d) [0x1c6d0c5]
/home/parveez/code/mysql/sql/mysqld(dispatch_command(THD*, COM_DATA const*, enum_server_command)+0x11d7) [0x1c630a9]
/home/parveez/code/mysql/sql/mysqld(do_command(THD*)+0x47c) [0x1c61b55]
/home/parveez/code/mysql/sql/mysqld() [0x1fbc47a]
/home/parveez/code/mysql/sql/mysqld() [0x29b99ff]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x8182) [0x7fc532c38182]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fc531b0047d]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (7fc4a8008e30): insert into t values('{"bc": ["x", "y"],"bc": ["z", "m"]}')
Connection ID (thread ID): 6
Status: NOT_KILLED

How to repeat:
start the server:

mysql>create table t(j json);                                                                                                                                                           Query OK, 0 rows affected (0.09 sec)

mysql> insert into t values('{"bc": ["x", "y"],"bc": ["z", "m"]}');
ERROR 2013 (HY000): Lost connection to MySQL server during query
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/home/parveez/code/mysql/mysql-test/var/tmp/mysqld.1.sock' (111)
ERROR: 
Can't connect to the server

ERROR 2006 (HY000): MySQL server has gone away