Bug #21427 Deadlock when closing Connection while calling Statement.getWarnings()
Submitted: 3 Aug 2006 10:33 Modified: 8 Sep 2006 12:52
Reporter: Klaus Halfmann Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:mysql-connector-java-3.1.13 OS:Windows (Windows-XP (should be any))
Assigned to: CPU Architecture:Any

[3 Aug 2006 10:33] Klaus Halfmann
Description:
   Statement.getWarnings()
and 
   Connection.close()

wil produce a deadlock wehen called in two seperate 
Threads at the same time.

How to repeat:
Assume two Threads T1, T2.

T1 calls (Prepared)Statement.getWarnings()

T2 calls Connection.close() for a Connection the Statement
   in T1 was derived from.

Please EMail me for a screenshot (in case I cant attach it later)

Suggested fix:
Fixed in mysql-connector-java-5.0.3

Add a 
   volatile boolean closing
as sticky flag to connection. 

When it is set Connection will block all usage
attempts without need for a synchronized block().

NEVER use the same Connection in more than one Threads
[3 Aug 2006 10:34] Klaus Halfmann
Screenshot of Deadlock from Eclipse debugger

Attachment: MySQL-Deadlock.gif (image/gif, text), 17.74 KiB.

[5 Sep 2006 7:06] Tonci Grgin
Hello.
Can you please post the following:
    * JVM version
    * OS version
    * Application Server version (if applicable)
    * The persistence engine (Hibernate, EJB, etc.) 
    * Small but complete test case demonstrating this behavior
[5 Sep 2006 7:56] Klaus Halfmann
%JAVA_HOME%\bin\java -version
java version "1.4.2_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)

OS version        : Mircrosoft WindowsXP Professional SP2
Application Server: jakarta-tomcat-4.1.31 (But Tomcat is not involved)
persistence engine: <none> Homegrown, LRU-based, PreparedStatementCache

I cannot supply you with a Testcase due to lack of time
(and since we upgraded to the next version of the connector)
But I hope the attched Stacktrace is quite clear.
[8 Sep 2006 12:52] Tonci Grgin
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Explanation: This is a duplicate of BUG#14972.