Bug #55591 Deadlock between DROP and CREATE DATABASE under LOCK TABLE
Submitted: 27 Jul 2010 21:49 Modified: 4 Feb 2011 16:21
Reporter: Elena Stepanova Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Locking Severity:S2 (Serious)
Version:5.1 OS:Any
Assigned to: CPU Architecture:Any

[27 Jul 2010 21:49] Elena Stepanova
Description:
The test case is similar to bug#54360, only with LOCK TABLE instead of OPEN HANDLER, and CREATE instead of ALTER database.

One connection locks a table in a schema, another connection attempts to drop the schema and starts waiting, then the first connection attempts to create another database and instead creates a deadlock.

Reproducible on 5.1.49, not reproducible on 5.5.

How to repeat:
# Test case

CREATE DATABASE db1;
CREATE TABLE db1.t1 (a INT);

--connect (con1, localhost, root)
LOCK TABLE db1.t1 WRITE;

--connection default
--send DROP DATABASE db1

--connection con1
--sleep 1
CREATE DATABASE db2;

--connection default
# We don't reach this
--reap

--exit

Suggested fix:
The problem is not reproducible with DROP or ALTER database instead of the last CREATE, because both DROP and ALTER immediately fail with ER_LOCK_OR_ACTIVE_TRANSACTION. Possibly it should also be the case for CREATE? In 5.5 it is the same for all of CREATE/ALTER/DROP DATABASE.
[4 Feb 2011 16:22] Omer Barnir
Fix exists in 5.5 and will not be back ported to 5.1