Bug #38492 assert in ha_maria.cc::external_lock
Submitted: 31 Jul 2008 15:07 Modified: 9 Jan 2009 14:55
Reporter: Sergei Golubchik Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Maria storage engine Severity:S3 (Non-critical)
Version:6.0 OS:Any
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[31 Jul 2008 15:07] Sergei Golubchik
Description:
mysqld: ha_maria.cc:2236: virtual int ha_maria::external_lock(THD*, int): Assertion `!thd->main_da.is_sent' failed.

How to repeat:
create table t1 (a int, b int) engine=maria transactional=1;
insert t1 values (1,2);

In one session:

insert t1 values (2,3), (sleep(10),sleep(20)), (4,5);

In another:

LOCK TABLES t1 write concurrent;
insert t1 values (7,8);

disconnect (without UNLOCK TABLES)
[31 Jul 2008 15:10] Sergei Golubchik
Even easier - just connect with one client, LOCK TABLES t1 write concurrent; disconnect, voila.
[13 Aug 2008 9:39] Oleksandr Byelkin
test suite script

Attachment: test.test (text/plain), 308 bytes.

[15 Aug 2008 7:00] Oleksandr Byelkin
=== modified file 'mysql-test/mysql-test-run.pl' (properties changed: -x to +x)
=== modified file 'mysql-test/r/maria.result'
--- mysql-test/r/maria.result   2008-07-10 15:20:07 +0000
+++ mysql-test/r/maria.result   2008-08-15 06:33:40 +0000
@@ -1901,3 +1901,9 @@ check table t2 extended;
 Table  Op      Msg_type        Msg_text
 test.t2        check   status  OK
 drop table t2;
+create table t1 (a int, b int) engine=maria transactional=1;
+insert t1 values (1,2);
+insert t1 values (2,3), (sleep(10),sleep(20)), (4,5);;
+LOCK TABLES t1 write concurrent;
+insert t1 values (7,8);
+drop table t1;

=== modified file 'mysql-test/t/maria.test'
--- mysql-test/t/maria.test     2008-07-10 15:20:07 +0000
+++ mysql-test/t/maria.test     2008-08-15 06:31:44 +0000
@@ -1188,6 +1188,21 @@ insert into t2 values (repeat('x',28)),
 check table t2 extended;
 drop table t2;

+#
+# BUG#38492 test suite
+#
+create table t1 (a int, b int) engine=maria transactional=1;
+insert t1 values (1,2);
+--send insert t1 values (2,3), (sleep(10),sleep(20)), (4,5);
+connect (root2,localhost,root,,test);
+--connection root2
+LOCK TABLES t1 write concurrent;
+insert t1 values (7,8);
+-- disconnect root2
+connection default;
+--reap
+drop table t1;
+
 --disable_result_log
 --disable_query_log
 eval set global storage_engine=$default_engine, maria_page_checksum=$default_ch
ecksum;

=== modified file 'sql/sql_class.cc'
--- sql/sql_class.cc    2008-07-20 22:39:29 +0000
+++ sql/sql_class.cc    2008-08-15 06:22:48 +0000
@@ -391,6 +391,7 @@ Diagnostics_area::reset_diagnostics_area
   m_total_warn_count= 0;
 #endif
   is_sent= FALSE;
+  is_quit= FALSE;
   /** Tiny reset in debug mode to see garbage right away */
   m_status= DA_EMPTY;
   DBUG_VOID_RETURN;

=== modified file 'sql/sql_class.h'
--- sql/sql_class.h     2008-07-14 22:06:19 +0000
+++ sql/sql_class.h     2008-08-15 06:22:48 +0000
@@ -1141,6 +1141,8 @@ public:
   };
   /** True if status information is sent to the client. */
   bool is_sent;
+  /** True if connection is closed */
+  bool is_quit;
   /** Set to make set_error_status after set_{ok,eof}_status possible. */
   bool can_overwrite_status;

=== modified file 'sql/sql_parse.cc'
--- sql/sql_parse.cc    2008-07-20 22:39:29 +0000
+++ sql/sql_parse.cc    2008-08-15 06:22:48 +0000
@@ -1172,6 +1172,7 @@ bool dispatch_command(enum enum_server_c
     general_log_print(thd, command, NullS);
     net->error=0;                              // Don't give 'abort' message
     thd->main_da.disable_status();              // Don't send anything back
+    thd->main_da.is_quit= TRUE;                 // Connection is closed
     error=TRUE;                                        // End server
     break;

=== modified file 'storage/maria/ha_maria.cc'
--- storage/maria/ha_maria.cc   2008-07-10 14:58:31 +0000
+++ storage/maria/ha_maria.cc   2008-08-15 06:22:48 +0000
@@ -2229,11 +2229,12 @@ int ha_maria::external_lock(THD *thd, in
         if (!trnman_decrement_locked_tables(trn))
         {
           /*
-            OK should not have been sent to client yet (ACID).
+            OK should not have been sent to client yet (ACID),
+            exception: connection is closed by client.
             This is a bit excessive, ACID requires this only if there are some
             changes to commit (rollback shouldn't be tested).
           */
-          DBUG_ASSERT(!thd->main_da.is_sent);
+          DBUG_ASSERT(!thd->main_da.is_sent || thd->main_da.is_quit);
           /* autocommit ? rollback a transaction */
 #ifdef MARIA_CANNOT_ROLLBACK
           if (ma_commit(trn))
[15 Aug 2008 8:01] 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/51700

2684 sanja@mysql.com	2008-08-15
      Ignore OK "sent" to user if it is connection termination (BUG#38492).
[18 Aug 2008 17:58] 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/51882

2684 sanja@mysql.com	2008-08-18
      Ignore OK "sent" to user if it is connection termination (BUG#38492).
[20 Aug 2008 15:02] 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/52063

2689 sanja@mysql.com	2008-08-20
      Ignore OK "sent" to user if it is connection termination (BUG#38492).
[20 Aug 2008 15:04] 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/52064

2689 sanja@mysql.com	2008-08-20
      Ignore OK "sent" to user if it is connection termination (BUG#38492).
[25 Aug 2008 12:25] 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/52441

2692 Sergei Golubchik	2008-08-25
      different fix for Bug#38492 assert in ha_maria.cc::external_lock
      that makes no changes outside of ha_maria.cc and also works in embedded
[25 Aug 2008 13:45] 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/52459

2692 Sergei Golubchik	2008-08-25
      different fix for Bug#38492 assert in ha_maria.cc::external_lock
      that makes no changes outside of ha_maria.cc and also works in embedded
[13 Sep 2008 22:20] Bugs System
Pushed into 6.0.6-alpha  (revid:serg@mysql.com-20080825122507-b9fyfo6gucgayrs1) (version source revid:hakan@mysql.com-20080716105246-eg0utbybp122n2w9) (pib:3)
[9 Jan 2009 14:55] MC Brown
A note has been added to the 6.0.6 changelog: 

Disconnecting a session where you have a applied a WRITE CONCURRENT lock on Maria tables would lead to a crash.