|
Adjusting urgency and priority to the standard levels.
Asif, do you have a reproduction for this issue?
Attached is patch for this issue with Asif's suggetion. (Thank you Asif.) plus making closingConnection synchronized as Dan suggested. I am still kind of fuzzy on what I have to check to make sure PooledConnection, XAConnection and XAResource methods behave correctly, but am trying to figure that out. Any tips would be greatly appreciated. suites.All passed, running derbyall now.
The ConnectionEventListner javadoc for connectionClosed says
Notifies this ConnectionEventListener that the application has called the method close on its representation of a pooled connection. It does not say whether the notification has been sent after the pooled connection is marked closed or before the pooled connection will be marked closed so it seems like it will be ok for us to mark currentConnectionHandle as null and then send the notifications. Section 11.2 & 12.5 of JDBC 4 specification indicate that the connection can be returned to the pool when the ConnectionEventListener.connectionClosed() is called, so the pooled connection must be (as Asif suggested) set into the correct state before the callback is made.
There's some potential for minor cleanup here - notifyClose() is synchronized and only ever called from closingConnection.
So with the current patch the synchronization will be obtained twice. Merging the two methods into one would avoid this and the indication that notifyClose() can be called from other code. Thanks Dan and Mamta for the input. Dan could you elaborate on your comment:
"Since the listeners can get a handed to the PooledConnection or XAConnection & XAResource we would just have to ensure that any method they can call on those interfaces behaves correctly." What exactly do I need to be checking? >> "Since the listeners can get a handed to the PooledConnection or XAConnection & XAResource we would just have to ensure that any method they can call on those interfaces behaves correctly."
> What exactly do I need to be checking? Nothing. :-) It's covered by my recent comment which probably was posted while you were writing yours. Sections 11.2 and 12.5 state that at the time of the callback they can return the PooledConnection to the pool for re-use, thus at time of the callback the PooledConnection must be disassociated from its previous logical connection. Note the logical connection is being closed, not the pooled connection. The buggy code passes the PooledConnection to the callbacks in a state where it is still associated to the just closed logical connection, my original concern was what is the expected state of the PooledConnection for the listeners: still associated or disassociated. I hadn't researched the details then. Attached is a revised patch rolling notifyClose into closingConnection().derby-2142_diff2.txt
Patch 2 seems to have lost the synchronization on the closingConnection() method.
--------------- This comment here is lacking the "why", it's really just describing the code so it's not adding any value. Why it needs to be before is the important information here. + // currentConnectionHandle = null; Thanks Dan for catching that! I was reeditting with emacs to get the white space right and botched the change #:(
I sure would feel better if I had a repro for this. running tests now on derby-2142_diff3.txt I added a test fixture DataSourceTest.testPooledReuseOnClose that covers this bug. Failed before revision 616141 and passes now on embedded.
It fails for network client, I didn't investigate that, just didn't run the test in that environment. Either a new bug should be added or it should be fixed under this bug. It would be good if you could make this code comment have value (see earlier issue comment): + // adding the why might help ensure the code doesn't get re-ordered in the future and explain it for anyone reading the code. Thanks for adding the test fixture Dan.
I think the client driver might have the same problem as the embedded driver. I'm currently working in that area of the code, and I'll investigate it. If required, I'd like to attach a patch to this issue. Hi Dan,
Thanks for the fixture. Here is the revised comment, gleaned from the comments in this issue and my understanding of it. // //At time of the callback the PooledConnection must be //disassociated from its previous logical connection. //If not, there is a risk that the Pooled //Connection could be returned to the pool, ready for pickup by a //new thread. This new thread then might obtain a java.sql.Connection //whose reference might get assigned to the currentConnectionHandle //field, meanwhile the previous thread completes the close making //the newly assigned currentConnectionHandle null, resulting in an NPE. I ported the embedded fix to 10.3, 10.2 and 10.1. If the client fix won't be going to all those branches, it might make sense to make a new issue for that.
Resolving this issue for embedded. Opened
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I also think in addition synchronization should be added, probably by making closingConnection() a synchronized method.