Bug #44664 valgrind warning for COMMIT_AND_CHAIN and ROLLBACK_AND_CHAIN
Submitted: 5 May 2009 11:14 Modified: 26 Jun 2009 2:18
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.35 OS:Linux (32-bit)
Assigned to: Davi Arnaut CPU Architecture:Any
Tags: COMMIT_AND_CHAIN, ROLLBACK_AND_CHAIN, valgrind

[5 May 2009 11:14] Shane Bester
Description:
Probably offspring from bug #33827
During some transaction stress tests I found a warning in 5.1.35

Thread 10:
Conditional jump or move depends on uninitialised value(s)
 at  begin_trans(THD*) (sql_parse.cc:201)
 by  end_trans(THD*, enum_mysql_completiontype) (sql_parse.cc:736)
 by  mysql_execute_command(THD*) (sql_parse.cc:4012)
 by  mysql_parse(THD*, char const*, unsigned, char const**) (sql_parse.cc:5902)
 by  dispatch_command(enum_server_command, THD*, char*, unsigned) (sql_parse.cc:1216)
 by  do_command(THD*) (sql_parse.cc:857)
 by  handle_one_connection (sql_connect.cc:1115)
 by  start_thread (in /lib/libpthread-2.5.so)
 by  clone (in /lib/libc-2.5.so)

Looks like lex->start_transaction_opt was not initialized, but something tried to use it.

end_trans code:

case ROLLBACK_AND_CHAIN:
  {
    thd->server_status&= ~SERVER_STATUS_IN_TRANS;
    if (ha_rollback(thd))
      res= -1;
    thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
    thd->transaction.all.modified_non_trans_table= FALSE;
    if (!res && (completion == ROLLBACK_AND_CHAIN))
      res= begin_trans(thd); <------------ 
    break;
  }

begin_trans code:

if (end_active_trans(thd))
    error= -1;
  else
  {
    LEX *lex= thd->lex;
    thd->options|= OPTION_BEGIN;
    thd->server_status|= SERVER_STATUS_IN_TRANS;
    if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
      error= ha_start_consistent_snapshot(thd);
  }

How to repeat:
will provide a testcase if i see it again.
[5 May 2009 11:16] MySQL Verification Team
okay, so I got COMMIT_AND_CHAIN warning too:

Conditional jump or move depends on uninitialised value(s)
 at  begin_trans(THD*) (sql_parse.cc:201)
 by  end_trans(THD*, enum_mysql_completiontype) (sql_parse.cc:723)
 by  mysql_execute_command(THD*) (sql_parse.cc:4006)
 by  mysql_parse(THD*, char const*, unsigned, char const**) (sql_parse.cc:5902)
 by  dispatch_command(enum_server_command, THD*, char*, unsigned) (sql_parse.cc:1216)
 by  do_command(THD*) (sql_parse.cc:857)
 by  handle_one_connection (sql_connect.cc:1115)
 by  start_thread (in /lib/libpthread-2.5.so)
 by  clone (in /lib/libc-2.5.so)
[5 May 2009 14:06] MySQL Verification Team
testcase1:

start transaction;
rollback work release;
commit work and chain no release;

testcase2:

start transaction;
rollback work release;
rollback work and chain no release;
[11 May 2009 23:54] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/73796

2874 Davi Arnaut	2009-05-11
      Bug#44664: valgrind warning for COMMIT_AND_CHAIN and ROLLBACK_AND_CHAIN
      
      The problem is that the internal variable used to specify a
      transaction with consistent read was being used outside the
      processing context of a START TRANSACTION WITH CONSISTENT
      SNAPSHOT statement. The practical consequence was that a
      consistent snapshot specification could leak to unrelated
      transactions on the same session.
      
      The solution is to ensure a consistent snapshot clause is
      only relied upon for the START TRANSACTION statement.
      
      This is already fixed in a similar way on 6.0.
     @ mysql-test/r/consistent_snapshot.result
        Add test case result for Bug#44664
     @ mysql-test/t/consistent_snapshot.test
        Add test case for Bug#44664
     @ sql/sql_parse.cc
        The WITH CONSISTENT SNAPSHOT clause is only valid for the
        START TRANSACTION statement.
[14 May 2009 10:59] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/74026

2880 Davi Arnaut	2009-05-11
      Bug#44664: valgrind warning for COMMIT_AND_CHAIN and ROLLBACK_AND_CHAIN
      
      The problem is that the internal variable used to specify a
      transaction with consistent read was being used outside the
      processing context of a START TRANSACTION WITH CONSISTENT
      SNAPSHOT statement. The practical consequence was that a
      consistent snapshot specification could leak to unrelated
      transactions on the same session.
      
      The solution is to ensure a consistent snapshot clause is
      only relied upon for the START TRANSACTION statement.
      
      This is already fixed in a similar way on 6.0.
     @ mysql-test/r/consistent_snapshot.result
        Add test case result for Bug#44664
     @ mysql-test/t/consistent_snapshot.test
        Add test case for Bug#44664
     @ sql/sql_parse.cc
        The WITH CONSISTENT SNAPSHOT clause is only valid for the
        START TRANSACTION statement.
[14 May 2009 11:02] Davi Arnaut
Queued to 5.1-bugteam
[14 May 2009 11:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/74030

3275 Davi Arnaut	2009-05-14 [merge]
      Merge Bug#44664 into mysql-6.0-bugteam.
[28 May 2009 8:16] Bugs System
Pushed into 5.1.36 (revid:joro@sun.com-20090528073639-yohsb4q1jzg7ycws) (version source revid:jimw@mysql.com-20090515174051-ndjvfd1e9hc9k9c3) (merge vers: 5.1.36) (pib:6)
[1 Jun 2009 20:26] Paul DuBois
Noted in 5.1.36 changelog.

A Valgrind warning related to transaction processing was silenced.

Setting report to NDI pending push into 6.0.x.
[17 Jun 2009 19:23] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090616183122-chjzbaa30qopdra9) (version source revid:davi.arnaut@sun.com-20090514111135-i221tcdlji3vv3n2) (merge vers: 6.0.12-alpha) (pib:11)
[26 Jun 2009 2:18] Paul DuBois
Noted in 5.4.4 changelog.
[12 Aug 2009 22:30] Paul DuBois
Noted in 5.4.2 changelog because next 5.4 version will be 5.4.2 and not 5.4.4.
[15 Aug 2009 1:50] Paul DuBois
Ignore previous comment about 5.4.2.
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-7.0.8 (revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-6.3.27 (revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (version source revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (merge vers: 5.1.37-ndb-6.3.27) (pib:11)
[26 Aug 2009 13:48] Bugs System
Pushed into 5.1.37-ndb-6.2.19 (revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (version source revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (merge vers: 5.1.37-ndb-6.2.19) (pib:11)
[27 Aug 2009 16:33] Bugs System
Pushed into 5.1.35-ndb-7.1.0 (revid:magnus.blaudd@sun.com-20090827163030-6o3kk6r2oua159hr) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[7 Oct 2009 20:21] Paul DuBois
The 5.4 fix has been pushed to 5.4.2.