Bug #111449 void Diagnostics_area::set_eof_status(THD*): Assertion `!is_set()' failed.
Submitted: 15 Jun 2023 20:49 Modified: 10 Aug 2023 0:24
Reporter: Yu Liang Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S6 (Debug Builds)
Version:8.0.33 OS:Ubuntu (20.04 LTS)
Assigned to: CPU Architecture:x86 (Intel(R) Core(TM) i7-10700 CPU)

[15 Jun 2023 20:49] Yu Liang
Description:
The latest version of the MySQL Server (version 8.0.33 debug build) (git commit hash: ea7087d8850) crashes with Assertion Failure when executing the following query:

Config from "/etc/mysql/conf.d/mysql.cnf":

```
[mysqld]
sql_mode = "NO_ENGINE_SUBSTITUTION"
```

```sql
drop database if exists test123;
create database test123;
use test123;
CREATE TABLE IF NOT EXISTS v0 ( c1 INT ) ;
INSERT INTO v0 SET c1 = c1 IS TRUE;
HANDLER v0 OPEN ;
HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ;
```

In the debug build, the server crashes with the following stack trace: 

```
mysql> HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ;
mysqld: /home/mysql/mysql-server/sql/sql_error.cc:394: void Diagnostics_area::set_eof_status(THD *): Assertion `!is_set()' failed.
2023-06-15T20:48:12Z UTC - mysqld got signal 6 ;
Most likely, you have hit a bug, but this error can also be caused by malfunctioning hardware.
BuildID[sha1]=1d55d4671b7469352fc317efb0121b604c26443d
Thread pointer: 0xfffef0001040
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 = ffff707f9538 thread_stack 0x100000
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(my_print_stacktrace(unsigned char const*, unsigned long)+0x60) [0x4e6bc30]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(print_fatal_signal(int)+0x340) [0x1a89320]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(handle_fatal_signal+0x16c) [0x1a896dc]
linux-vdso.so.1(__kernel_rt_sigreturn+0) [0xffffada477a0]
/lib/aarch64-linux-gnu/libc.so.6(gsignal+0xe0) [0xffffad0bbd78]
/lib/aarch64-linux-gnu/libc.so.6(abort+0x114) [0xffffad0a8aac]
/lib/aarch64-linux-gnu/libc.so.6(+0x2d490) [0xffffad0b5490]
/lib/aarch64-linux-gnu/libc.so.6(+0x2d4f4) [0xffffad0b54f4]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(Diagnostics_area::set_eof_status(THD*)+0x1cc) [0x153cbc8]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(my_eof(THD*)+0x60) [0x148174c]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(Sql_cmd_handler_read::execute(THD*)+0x292c) [0x1584c28]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(mysql_execute_command(THD*, bool)+0x281c) [0x162bcd8]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(dispatch_sql_command(THD*, Parser_state*)+0x1124) [0x16252c0]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(dispatch_command(THD*, COM_DATA const*, enum_server_command)+0x5434) [0x161e224]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld(do_command(THD*)+0xb8c) [0x16228f4]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld() [0x1a59a64]
/home/mysql/mysql-server/bld/runtime_output_directory/mysqld() [0x655c1a0]
/lib/aarch64-linux-gnu/libpthread.so.0(+0x7624) [0xffffad9ed624]
/lib/aarch64-linux-gnu/libc.so.6(+0xd149c) [0xffffad15949c]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (fffef01f0090): HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100
Connection ID (thread ID): 14
Status: NOT_KILLED
```

How to repeat:
Steps to repeat the Assertion Failure:
1. Download the MySQL Server source code from the official github repo: `https://github.com/mysql/mysql-server`
2. Checkout to the latest mysql released version: 8.0.33 (hash: `ea7087d8850`)
3. Compile MySQL using the command: 

```
mkdir -p bld
cd bld
cmake .. -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../boost -DWITH_UNIT_TESTS=OFF -DWITH_DEBUG=1
make
```

4. Run the MySQL Server with command: 

```
./bin/mysqld --basedir=$(pwd) --datadir=$(pwd)/data_all/ori_data --port=7000  --socket=/tmp/mysql_0.sock --mysqlx=OFF --performance_schema=OFF
```

5. Setup the MySQL Server config in the path: "/etc/mysql/conf.d/mysql.cnf"

```
[mysqld]
sql_mode = "NO_ENGINE_SUBSTITUTION"
```

6. Run the MySQL Client with the PoC:

```
./bin/mysql --port=7000 --user=root --socket=/tmp/mysql_0.sock < poc_0.sql
```

where `poc_0.sql` is:

```sql
drop database if exists test123;
create database test123;
use test123;
CREATE TABLE IF NOT EXISTS v0 ( c1 INT ) ;
INSERT INTO v0 SET c1 = c1 IS TRUE;
HANDLER v0 OPEN ;
HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ;
```

Suggested fix:
The server should continue running instead of crashing by Assertion Failure.
[16 Jun 2023 6:36] MySQL Verification Team
Hello Yu Liang,

Thank you for the report and test case.
Observed that 8.0.33 debug build is affected.

regards,
Umesh
[16 Jun 2023 6:37] MySQL Verification Team
-- release build - not affected
 ./mtr bug111449 --nocheck-testcases
Logging: ./mtr  bug111449 --nocheck-testcases
MySQL Version 8.0.33
Checking supported features
Using 'all' suites
Collecting tests
Checking leftover processes
Removing old var directory
 - WARNING: Using the 'mysql-test/var' symlink
Creating var directory '/export/home/tmp/ushastry/mysql-8.0.33/mysql-test/var'
Installing system database
Using parallel: 1

==============================================================================
                  TEST NAME                       RESULT  TIME (ms) COMMENT
------------------------------------------------------------------------------
drop database if exists test123;
Warnings:
Note    1008    Can't drop database 'test123'; database doesn't exist
create database test123;
use test123;
CREATE TABLE IF NOT EXISTS v0 ( c1 INT ) ;
INSERT INTO v0 SET c1 = c1 IS TRUE;
HANDLER v0 OPEN ;
HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ;
[ 50%] main.bug111449                            [ fail ]
        Test ended at 2023-06-16 08:35:42

CURRENT_TEST: main.bug111449
mysqltest: At line 7: Query 'HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ' failed.
ERROR 3146 (22032): Invalid data type for JSON data in argument 2 to function member of; a JSON string or JSON type is required.
safe_process[17879]: Child process: 17880, exit: 1

 - the logfile can be found in '/export/home/tmp/ushastry/mysql-8.0.33/mysql-test/var/log/main.bug111449/bug111449.log'

[100%] shutdown_report                           [ pass ]

-- debug build - affected
 ./mtr bug111449 --nocheck-testcases --debug-server
Logging: ./mtr  bug111449 --nocheck-testcases --debug-server
MySQL Version 8.0.33
Checking supported features
 - Binaries are debug compiled
Using 'all' suites
Collecting tests
Checking leftover processes
Removing old var directory
 - WARNING: Using the 'mysql-test/var' symlink
Creating var directory '/export/home/tmp/ushastry/mysql-8.0.33/mysql-test/var'
Installing system database
Using parallel: 1

==============================================================================
                  TEST NAME                       RESULT  TIME (ms) COMMENT
------------------------------------------------------------------------------
drop database if exists test123;
Warnings:
Note    1008    Can't drop database 'test123'; database doesn't exist
create database test123;
use test123;
CREATE TABLE IF NOT EXISTS v0 ( c1 INT ) ;
INSERT INTO v0 SET c1 = c1 IS TRUE;
HANDLER v0 OPEN ;
HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ;
[ 50%] main.bug111449                            [ fail ]
        Test ended at 2023-06-16 08:36:03

CURRENT_TEST: main.bug111449
mysqltest: At line 7: Query 'HANDLER v0 READ FIRST WHERE c1 MEMBER ( c1 ) IS NOT FALSE LIMIT 100 , 100 ' failed.
ERROR 2013 (HY000): Lost connection to MySQL server during query

-bt
#0  0x00007f753076aaa1 in pthread_kill () from /lib64/libpthread.so.0
#1  0x0000000003f9296e in my_write_core(int) ()
#2  0x00000000032365f5 in handle_fatal_signal ()
#3  <signal handler called>
#4  0x00007f752e9a4387 in raise () from /lib64/libc.so.6
#5  0x00007f752e9a5a78 in abort () from /lib64/libc.so.6
#6  0x00007f752e99d1a6 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f752e99d252 in __assert_fail () from /lib64/libc.so.6
#8  0x000000000307000a in Diagnostics_area::set_eof_status(THD*) ()
#9  0x000000000302b9b4 in my_eof(THD*) ()
#10 0x000000000308965c in Sql_cmd_handler_read::execute(THD*) ()
#11 0x00000000030c4964 in mysql_execute_command(THD*, bool) ()
#12 0x00000000030c5dc9 in dispatch_sql_command(THD*, Parser_state*) ()
#13 0x00000000030c752b in dispatch_command(THD*, COM_DATA const*, enum_server_command) ()
#14 0x00000000030c926e in do_command(THD*) ()
#15 0x0000000003227bb7 in handle_connection ()
#16 0x0000000004743af9 in pfs_spawn_thread ()
#17 0x00007f7530765ea5 in start_thread () from /lib64/libpthread.so.0
#18 0x00007f752ea6cb2d in clone () from /lib64/libc.so.6
[10 Aug 2023 0:24] Jon Stephens
Fixed in MySQL 8.2.0.

Does not affect a release.

Closed.