Bug #76734 assertion in XA ROLLBACK if transaction body is empty and binlog enabled
Submitted: 17 Apr 2015 12:37 Modified: 16 Jun 2015 5:04
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S2 (Serious)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any

[17 Apr 2015 12:37] Sven Sandberg
Description:
If an empty XA transaction is prepared, a subsequent XA ROLLBACK statement triggers an assertion:

Thread 1 (Thread 0x7f0dd0337700 (LWP 31231)):
#0  pthread_kill() from /lib/x86_64-linux-gnu/libpthread.so.0
#1  my_write_core(sig=6)
    mysys/stacktrace.c:247:
  pthread_kill(my_thread_self(), sig);
#2  handle_fatal_signal(sig=6)
    sql/signal_handler.cc:221:
    my_write_core(sig);
#3  <signal handler called>
#4  raise() from /lib/x86_64-linux-gnu/libc.so.6
#5  abort() from /lib/x86_64-linux-gnu/libc.so.6
#6  0x00007f0dd5abbb86 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#7  __assert_fail() from /lib/x86_64-linux-gnu/libc.so.6
#8  MYSQL_BIN_LOG::rollback(this=0x2b42ac0 <mysql_bin_log>, thd=0x7f0d7c012060, all=true)
    sql/binlog.cc:1928:
    DBUG_ASSERT(cache_mngr != NULL
#9  ha_rollback_trans(thd=0x7f0d7c012060, all=true)
    sql/handler.cc:1857:
    error= tc_log->rollback(thd, all);
#10 xa_trans_force_rollback(thd=0x7f0d7c012060)
    sql/xa.cc:270:
  if (ha_rollback_trans(thd, true))
#11 Sql_cmd_xa_rollback::trans_xa_rollback(this=0x7f0d7c194ae8, thd=0x7f0d7c012060)
    sql/xa.cc:497:
  bool res= xa_trans_force_rollback(thd);
#12 Sql_cmd_xa_rollback::execute(this=0x7f0d7c194ae8, thd=0x7f0d7c012060)
    sql/xa.cc:516:
  bool st= trans_xa_rollback(thd);
#13 mysql_execute_command(thd=0x7f0d7c012060)
    sql/sql_parse.cc:4431:
    res= lex->m_sql_cmd->execute(thd);
#14 mysql_parse(thd=0x7f0d7c012060, parser_state=0x7f0dd0336210)
    sql/sql_parse.cc:5110:
            error= mysql_execute_command(thd);
#15 dispatch_command(command=COM_QUERY, thd=0x7f0d7c012060, packet=0x7f0d7c009851 "XA ROLLBACK '1'", packet_length=15)
    sql/sql_parse.cc:1213:
    mysql_parse(thd, &parser_state);
#16 do_command(thd=0x7f0d7c012060)
    sql/sql_parse.cc:797:
                                 static_cast<size_t>(packet_length-1));
#17 handle_connection(arg=0x478bd00)
    sql/conn_handler/connection_handler_per_thread.cc:299:
        if (do_command(thd))
#18 pfs_spawn_thread(arg=0x4816590)
    storage/perfschema/pfs.cc:2147:
  (*user_start_routine)(user_arg);
#19 start_thread() from /lib/x86_64-linux-gnu/libpthread.so.0
#20 clone() from /lib/x86_64-linux-gnu/libc.so.6

How to repeat:
--source include/have_log_bin.inc
XA START '1';
XA END '1';
XA PREPARE '1';
XA ROLLBACK '1';
[16 Jun 2015 5:04] Erlend Dahl
[12 Jun 2015 9:37] David Moss 

The following was noted in the 5.7.8 changelog:

When log_bin=ON, if a read-only XA transaction was prepared but had an empty
body, a subsequent XA ROLLBACK caused an assertion.