Bug #32528 Global read lock with a low priority write lock causes a server crash
Submitted: 20 Nov 2007 14:41 Modified: 12 Dec 2007 19:54
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Locking Severity:S3 (Non-critical)
Version:5.0/5.1BK OS:Any
Assigned to: Davi Arnaut CPU Architecture:Any
Tags: crash, flush tables with read lock, write lock

[20 Nov 2007 14:41] Davi Arnaut
Description:
When trying to aspire a global read lock, the reload_acl_and_cache()
function fails to properly check if the thread has a write locked table,
which later my cause a server crash or deadlock.

Regression probably introduced by fix to Bug#9459

Might be the same issue of Bug#18884, some tests fail to properly
reset low_priority_updates.

How to repeat:
set session low_priority_updates=1;
create table t1 (i int);
lock tables t1 write;
flush tables with read lock;

Suggested fix:
===== sql/sql_parse.cc 1.716 vs edited =====
--- 1.716/sql/sql_parse.cc	2007-11-01 19:48:11 -03:00
+++ edited/sql/sql_parse.cc	2007-11-20 12:25:24 -02:00
@@ -6412,7 +6412,7 @@
 
         for (; lock_p < end_p; lock_p++)
         {
-          if ((*lock_p)->type == TL_WRITE)
+          if ((*lock_p)->type >= TL_WRITE_LOW_PRIORITY)
           {
             my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
             return 1;
[22 Nov 2007 12:18] 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/38269

ChangeSet@1.2563, 2007-11-22 10:18:19-02:00, davi@endora.local +3 -0
  Bug#32528 Global read lock with a low priority write lock causes a server crash
  
  FLUSH TABLES WITH READ LOCK fails to properly detect write locked
  tables when running under low priority updates.
  
  The problem is that when trying to aspire a global read lock, the
  reload_acl_and_cache() function fails to properly check if the thread
  has a low priority write lock, which later my cause a server crash or
  deadlock.
  
  The solution is to simple check if the thread has any type of the
  possible exclusive write locks.
[6 Dec 2007 9:55] Bugs System
Pushed into 5.0.54
[6 Dec 2007 9:59] Bugs System
Pushed into 5.1.23-rc
[6 Dec 2007 10:01] Bugs System
Pushed into 6.0.5-alpha
[12 Dec 2007 19:54] Paul Dubois
Noted in 5.0.54, 5.1.23, 6.0.5 changelogs.

For FLUSH TABLES WITH READ LOCK, the server failed to properly detect
write-locked tables when running with low-priority updates, resulting
in a crash or deadlock.