#1169 - Memory leak - DefaultTransactionThreadLocal holding reference to transaction

This commit is contained in:
Rob Bygrave
2017-10-16 22:14:48 +13:00
parent f6e5446dab
commit 6e2712ea49
2 changed files with 4 additions and 5 deletions
@@ -153,7 +153,7 @@ public class ScopeTrans implements Thread.UncaughtExceptionHandler {
}
protected void restoreSuspended() {
if (suspendedTransaction != null) {
if (created || suspendedTransaction != null) {
// put the previously suspended transaction
// back onto the ThreadLocal or equivalent
scopeMgr.replace(suspendedTransaction);
@@ -779,6 +779,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
newTransaction = false;
suspended = t;
t = null;
transactionScopeManager.replace(null);
} else {
// create a new Transaction based on TxType and t
@@ -795,13 +796,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
isoLevel = isolation.getLevel();
}
t = transactionManager.createTransaction(true, isoLevel);
// note ScopeTrans.onFinally() restores the suspended transaction
transactionScopeManager.replace(t);
}
}
// replace the current transaction ... ScopeTrans.onFinally()
// has the job of restoring the suspended transaction
transactionScopeManager.replace(t);
return new ScopeTrans(rollbackOnChecked, newTransaction, t, txScope, suspended, transactionScopeManager);
}