Bug #31919 NPE synchronising around cancelTimeoutMutex in executeQuery()
Submitted: 29 Oct 2007 15:46 Modified: 30 Apr 2013 9:19
Reporter: Adam Pollock Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.5 OS:Windows (Windows XP Professional, Build 2600.xpsp_sp2_gdr.070227-2254 (Service Pack 2))
Assigned to: Alexander Soklakov CPU Architecture:Any
Tags: cancelTimeoutMutex, executeQuery(), realClose(), StatementImpl, synchronization

[29 Oct 2007 15:46] Adam Pollock
Description:
There are occassions where a NullPointerException is thrown, as we are attempting to synchronize around an object with has been nulled.  This occurs in StatementImpl.java, on line 1398.

We attempt to synchronize around this.cancelTimeoutMutex, however this has been nulled due to an apparent call to realClose(). The problem lies in an apparent lack of synchronization within the realClose() method itself.

Following the possible code flows as much as I could, it seems that either directly closing the statement, or calling the "public synchronized int[] executeBatch() throws SQLException" method are the only ways capable of calling realClose() without synchronizing around locallyScopedConn.getMutex().

How to repeat:
Unfortunately, due to the thread based nature of this problem, it is quite hard to repeat. We generally see it happen approximately every 500000 or so times whilst attempting to execute queries.

Suggested fix:
It appears as though either the deliberate nulling of an object used purely as a monitor for synchronization around is not required, or the execution of batch queries should also be synchronized around locallyScopedConn.getMutex().
[12 Feb 2008 13:24] Tonci Grgin
Hi Adam and thanks for your report. Sorry for the delay in processing but I really don't know where to start... Just to be on the safe side, I notified our c/J team leader of your report.
[3 Sep 2008 14:55] Mark Matthews
I don't see where in 5.1.6 or newer where we null this out in realClose. Perhaps it's worth trying a nightly snapshot of 5.1.7 to see if the problem has gone away? See http://downloads.mysql.com/snapshots.php for a nightly snapshot build.
[3 Oct 2008 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[30 Apr 2013 9:19] Alexander Soklakov
Hi Adam,

There is no feedback since Sep 2008 and synchronization model changed significantly since c/J 5.1.5, so I close this report as "Can't repeat". Please, feel free to reopen it if the problem still exists in current driver.