Bug #30632 HANDLER read failure causes hang
Submitted: 24 Aug 2007 20:44 Modified: 9 Oct 2007 17:29
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0BK/5.1BK OS:Any
Assigned to: Davi Arnaut

[24 Aug 2007 20:44] Davi Arnaut
Description:
The first HANDLER ... READ which yields a failure due to conditions not met or other errors, leaves the table in a locked state.

How to repeat:
mysql> drop table tbl;
Query OK, 0 rows affected (0.00 sec)

mysql> create table tbl (idx int);
Query OK, 0 rows affected (0.41 sec)

mysql> handler tbl open as tbl_alias;
Query OK, 0 rows affected (0.00 sec)

mysql> handler tbl_alias read idx next;
ERROR 1176 (HY000): Key 'idx' doesn't exist in table 'tbl_alias'
mysql> handler tbl_alias read idx next; #hangs

or

mysql> handler tbl open as tbl_alias;
Query OK, 0 rows affected (0.00 sec)

mysql> HANDLER tbl_alias READ idx next WHERE whatever > 0;
ERROR 1054 (42S22): Unknown column 'whatever' in 'field list'
mysql> HANDLER tbl_alias READ idx next WHERE inexistent > 0; #hangs

Suggested fix:
Always unlock the table locks on the error path.

Index: mysql-5.0-runtime/sql/sql_handler.cc
===================================================================
--- mysql-5.0-runtime.orig/sql/sql_handler.cc   2007-08-24 16:31:54.000000000 -0400
+++ mysql-5.0-runtime/sql/sql_handler.cc        2007-08-24 16:32:55.000000000 -0400
@@ -440,7 +440,7 @@
       cond->cleanup();                          // File was reopened
     if ((!cond->fixed &&
         cond->fix_fields(thd, &cond)) || cond->check_cols(1))
-      goto err0;
+      goto err;
   }
 
   if (keyname)
@@ -448,13 +448,13 @@
     if ((keyno=find_type(keyname, &table->s->keynames, 1+2)-1)<0)
     {
       my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), keyname, tables->alias);
-      goto err0;
+      goto err;
     }
   }
 
   if (insert_fields(thd, &thd->lex->select_lex.context,
                     tables->db, tables->alias, &it, 0))
-    goto err0;
+    goto err;
 
   protocol->send_fields(&list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
[24 Aug 2007 21:09] Miguel Solorzano
Thank you for the bug report.
[24 Aug 2007 23: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/33069

ChangeSet@1.2502, 2007-08-24 20:25:43-03:00, davi@moksha.local +3 -0
  Bug#30632 HANDLER read failure causes hang
  
  If, after the tables are locked, one of the conditions to read from a HANDLER table is not met, the handler code wrongly jumps to a error path that won't unlock the tables.
  
  The fix is simply to correct the code to jump to the (same) error path that unlocks the tables.
[27 Aug 2007 13:37] 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/33152

ChangeSet@1.2503, 2007-08-27 10:37:12-03:00, davi@moksha.local +3 -0
  Bug#30632 HANDLER read failure causes hang
  
  If, after the tables are locked, one of the conditions to read from a
  HANDLER table is not met, the handler code wrongly jumps to a error path
  that won't unlock the tables.
  
  The user-visible effect is that after a error in a handler read command,
  all subsequent handler operations on the same table will hang.
  
  The fix is simply to correct the code to jump to the (same) error path that
  unlocks the tables.
[28 Aug 2007 22:14] Davi Arnaut
pushed in 5.0-runtime
[29 Aug 2007 22: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/33403

ChangeSet@1.2582, 2007-08-29 19:00:49-03:00, davi@moksha.local +2 -0
  Post-merge fixes for Bug#30632
[29 Aug 2007 22:06] Davi Arnaut
Pushed in 5.1-runtime
[7 Sep 2007 8:08] Bugs System
Pushed into 5.1.23-beta
[7 Sep 2007 8:10] Bugs System
Pushed into 5.0.50
[9 Oct 2007 17:29] Paul Dubois
Noted in 5.0.50, 5.1.23 changelogs.

A failed HANDLER ... READ operation could leave the table in a locked
state.