JTASessionContext.CleanupSynch does not remove sessions from currentSessionMap

Description

We are using JTASessionContext, CMTTransaction and WebSphereExtendedJTATransactionLookup. We have experienced some memmory leak problems and after closer inspection we have found that Hibernate sessions are not removed from currentSessionMap inside JTASessionContext.

Method JTASessionContext.CleanupSynch.afterCompletion() is called as expected but code "context.currentSessionMap.remove( txn );" does not remove session from Map because of key's hashcode has changed. This is due to fact that com.ibm.websphere.jtaextensions.ExtendedJTATransaction.hashCode is actually ID of underlaying transaction. But if it comes to the afterCompletion method in CleanupSynch the underlaying transaction is already closed. Closed transaction has ID 0 (default value) and it is different from ID under which the Hibernate session was previously inserted into Map.

Possible patch is in attachements.

Attachments

5
  • 27 May 2008, 03:30 PM
  • 27 May 2008, 03:25 PM
  • 03 Feb 2007, 02:52 PM
  • 03 Feb 2007, 02:51 PM
  • 25 May 2006, 03:20 PM

cloned from

Activity

Steve EbersoleSeptember 9, 2008 at 11:23 PM

Gary, thanks for reporting and looking into this. However, pasting the diff directly into a comment here makes it really unreadable.

It looks like I just forgot to use the "transaction identifier" explicitly when:
1) getting from the map
2) removing from map (in CleanupSynch)

(see the patch or fisheye logs on the linked case).

Gary SargentSeptember 4, 2008 at 1:52 PM

Having looked into this further, in JTASessionContext, the map is being populated with a different key to that used when it is being read (in the two places a get and a remove are performed on the Map).

This will work fine for non-Websphere transaction lookups as the default implementation returns the transaction, which is what is used for the get / remove.

For WebSphere, this won't work as this uses a different key. This means a new session is ALWAYS created even if one exists, and sessions are NEVER removed!

Solution is to ensure the correct key is used in the get and remove methods on the Map. Diff for JTASessionContext.java against 3.3.0 is:

104c104,107
< Session currentSession = ( Session ) currentSessionMap.get( txn );

> Object txnIdentifier = factory.getSettings().getTransactionManagerLookup() == null
> ? txn
> : factory.getSettings().getTransactionManagerLookup().getTransactionIdentifier( txn );
> Session currentSession = ( Session ) currentSessionMap.get( txnIdentifier );
110c113
< txn.registerSynchronization( buildCleanupSynch( txn ) );

> txn.registerSynchronization( buildCleanupSynch( txnIdentifier ) );
122,124d124
< Object txnIdentifier = factory.getSettings().getTransactionManagerLookup() == null
< ? txn
< : factory.getSettings().getTransactionManagerLookup().getTransactionIdentifier( txn );
131,132c131,132
< private CleanupSynch buildCleanupSynch(Transaction txn) {
< return new CleanupSynch( txn, this );

> private CleanupSynch buildCleanupSynch(Object txnIdentifier) {
> return new CleanupSynch( txnIdentifier, this );
183c183
< private Transaction txn;

> private Object txnIdentifier;
186,187c186,187
< public CleanupSynch(Transaction txn, JTASessionContext context) {
< this.txn = txn;

> public CleanupSynch(Object txnIdentifier, JTASessionContext context) {
> this.txnIdentifier = txnIdentifier;
201c201
< context.currentSessionMap.remove( txn );

> Object x = context.currentSessionMap.remove( txnIdentifier );

Gary SargentSeptember 4, 2008 at 12:09 PM

I've tested this with WebSphere V6.1.0.19 and Hibernate 3.3.0 SP1 (CMT and Oracle).

Sessions are still not being removed from currentSessionMap. I've added debug into JTASessionContext.CleanupSynch.afterCompletion(), and the remove from map method always returns null.

I notice in WebSphereExtendedJTATransactionLookup that the patch in this JIRA entry to cache the localId reference in getLocalId() is not present in the official release. Should this not have made it into 3.3.0 GA?

Steve EbersoleMay 27, 2008 at 4:49 PM

Missed a commit

LakshmiMay 27, 2008 at 3:30 PM

Tested with the JTASessionContext patch on 3.2.5ga and it works as expected. Thanks for the patch. Sessions are cleared from currentSessionMap on transaction completion. This is high priority bug for us as we are unable to run the application (hibernate 3.2.5 + WAS 6.0.2.21 + CMT) for 5 hour performance run continuously without the patch. Migrating to 3.3.0CR1 did not fix the issue.

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created May 25, 2006 at 3:20 PM
Updated September 9, 2008 at 11:23 PM
Resolved May 27, 2008 at 4:49 PM

Flag notifications