Bug #99377 Assertion `thd->get_transaction()->is_empty(Transaction_ctx::STMT)' failed in
Submitted: 28 Apr 2020 0:24 Modified: 28 Apr 2020 6:54
Reporter: Roel Van de Paar Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S6 (Debug Builds)
Version:5.5,5.6,5.7,8.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: debug

[28 Apr 2020 0:24] Roel Van de Paar
Description:
2020-04-28T00:04:04.229813Z 4 [ERROR] Column count of mysql.general_log is wrong. Expected 6, found 1. The table is probably corrupted
2020-04-28T00:04:04.229845Z 4 [ERROR] Failed to write to mysql.general_log:
mysqld: /t/mysql-server-5.7_dbg/sql/transaction.cc:84: bool trans_check_state(THD*): Assertion `thd->get_transaction()->is_empty(Transaction_ctx::STMT)' failed.

Core was generated by `/test/MS190320-mysql-8.0.19-linux-x86_64-dbg/bin/mysqld --no-defaults --core-fi'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x7f5474968700 (LWP 578151))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005593d1d97465 in my_write_core (sig=6)
    at /data/git/mysql-sever-8.0_dbg/mysys/stacktrace.cc:306
#2  0x00005593d0959910 in handle_fatal_signal (sig=6)
    at /data/git/mysql-sever-8.0_dbg/sql/signal_handler.cc:169
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x00007f54749a9801 in __GI_abort () at abort.c:79
#6  0x00007f547499939a in __assert_fail_base (
    fmt=0x7f5474b207d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x5593d3167830 "thd->get_transaction()->is_empty(Transaction_ctx::STMT)", file=file@entry=0x5593d31677f8 "/data/git/mysql-sever-8.0_dbg/sql/transaction.cc", 
    line=line@entry=105, 
    function=function@entry=0x5593d3167cf0 <trans_check_state(THD*)::__PRETTY_FUNCTION__> "bool trans_check_state(THD*)") at assert.c:92
#7  0x00007f5474999412 in __GI___assert_fail (
    assertion=0x5593d3167830 "thd->get_transaction()->is_empty(Transaction_ctx::STMT)", 
    file=0x5593d31677f8 "/data/git/mysql-sever-8.0_dbg/sql/transaction.cc", line=105, 
    function=0x5593d3167cf0 <trans_check_state(THD*)::__PRETTY_FUNCTION__> "bool trans_check_state(THD*)") at assert.c:101
#8  0x00005593d08ea571 in trans_check_state (thd=0x7f541e020000)
    at /data/git/mysql-sever-8.0_dbg/sql/transaction.cc:105
#9  0x00005593d08eb283 in trans_rollback (thd=0x7f541e020000)
    at /data/git/mysql-sever-8.0_dbg/sql/transaction.cc:401
#10 0x00005593d069e557 in THD::cleanup (this=0x7f541e020000)
    at /data/git/mysql-sever-8.0_dbg/sql/sql_class.cc:941
#11 0x00005593d069e9b7 in THD::release_resources (this=0x7f541e020000)
    at /data/git/mysql-sever-8.0_dbg/sql/sql_class.cc:1039
#12 0x00005593d0943634 in handle_connection (arg=0x7f5466bed660)
    at /data/git/mysql-sever-8.0_dbg/sql/conn_handler/connection_handler_per_thread.cc:309
#13 0x00005593d25d4497 in pfs_spawn_thread (arg=0x7f547408c2a0)
    at /data/git/mysql-sever-8.0_dbg/storage/perfschema/pfs.cc:2854
#14 0x00007f5476aec6db in start_thread (arg=0x7f5474968700) at pthread_create.c:463
#15 0x00007f5474a8a88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

How to repeat:
DROP TABLE mysql.general_log;
CREATE TABLE mysql.general_log(a int);
SET GLOBAL general_log='ON';
SET GLOBAL log_output='TABLE';
SELECT 1;

Suggested fix:
1) Do not allow turning on general_log if mysql.general_log is corrupted 
2) Sever is aware of possible corruption (ref error log in description); no need to crash in debug
[28 Apr 2020 6:54] MySQL Verification Team
Hello Roel,

Thank you for the report and test case.
Observed that 5.7.30, 8.0.20 debug builds are affected.

regards,
Umesh