Bug #70704 Deadlock using UpdatableResultSet
Submitted: 23 Oct 2013 15:16 Modified: 19 Apr 2017 0:52
Reporter: RUDOLF H��CKEL Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:mysql-connector-java-5.1.23 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[23 Oct 2013 15:16] RUDOLF H��CKEL
Thread: 'CAB', State is 'BLOCKED'

Thread: 'ABC', State is 'BLOCKED'

Closing two Objects in different Threads leads to deadlock.

First Stacktrace blocks the UpdatableResultSet and StatementImpl.close trys synchronized (checkClosed().getConnectionMutex()) 

Second Stacktrace just the other way from  getConnectionMutex() to UpdatableResultSet.realClose

How to repeat:
Two Threads one closing a Resulset the other closing the statement at the same time

Suggested fix:
public void realClose(boolean calledExplicitly) throws SQLException {
        synchronized (checkClosed().getConnectionMutex()) {
[24 Oct 2013 10:45] Alexander Soklakov
Hi Rudolf,

Thanks for your report!

First, please try the latest c/j 5.1.26 or at least c/j 5.1.24 where we updated our synchronization infrastructure.

However I see in code that we still have an old style synchronization in UpdatableResultSet, and we really need to fix it too.

Verified by code review.
[19 Apr 2017 0:52] Daniel So
Posted by developer:
Added the following entry to the Connector/J 5.1.42 changelog:

"When an UpdatableResultSet was used, trying to close the result set and its prepared statement simultaneously by different threads might result in a deadlock. This fix updates the synchronization mechanism for UpdatableResultSet to avoid the issue."