Skip to content

Commit 2e4eb9f

Browse files
jhoellerunknown
authored and
unknown
committed
Resource-based PlatformTransactionManager implementations defensively catch Throwable in doBegin in order to reliably close resource in case of OutOfMemoryError
Issue: SPR-10755
1 parent 504d5da commit 2e4eb9f

File tree

7 files changed

+10
-11
lines changed

7 files changed

+10
-11
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
238238
}
239239
}
240240

241-
catch (Exception ex) {
241+
catch (Throwable ex) {
242242
DataSourceUtils.releaseConnection(con, this.dataSource);
243243
throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
244244
}

spring-jms/src/main/java/org/springframework/jms/connection/JmsTransactionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -196,7 +196,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
196196
TransactionSynchronizationManager.bindResource(
197197
getConnectionFactory(), txObject.getResourceHolder());
198198
}
199-
catch (JMSException ex) {
199+
catch (Throwable ex) {
200200
if (con != null) {
201201
try {
202202
con.close();

spring-orm-hibernate4/src/main/java/org/springframework/orm/hibernate4/HibernateTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
500500
txObject.getSessionHolder().setSynchronizedWithTransaction(true);
501501
}
502502

503-
catch (Exception ex) {
503+
catch (Throwable ex) {
504504
if (txObject.isNewSession()) {
505505
try {
506506
if (session.getTransaction().isActive()) {

spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
583583
txObject.getSessionHolder().setSynchronizedWithTransaction(true);
584584
}
585585

586-
catch (Exception ex) {
586+
catch (Throwable ex) {
587587
if (txObject.isNewSession()) {
588588
try {
589589
if (session.getTransaction().isActive()) {

spring-orm/src/main/java/org/springframework/orm/jdo/JdoTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public int getTimeout() {
366366
closePersistenceManagerAfterFailedBegin(txObject);
367367
throw ex;
368368
}
369-
catch (Exception ex) {
369+
catch (Throwable ex) {
370370
closePersistenceManagerAfterFailedBegin(txObject);
371371
throw new CannotCreateTransactionException("Could not open JDO PersistenceManager for transaction", ex);
372372
}

spring-orm/src/main/java/org/springframework/orm/jpa/JpaTransactionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public int getTimeout() {
425425
closeEntityManagerAfterFailedBegin(txObject);
426426
throw ex;
427427
}
428-
catch (Exception ex) {
428+
catch (Throwable ex) {
429429
closeEntityManagerAfterFailedBegin(txObject);
430430
throw new CannotCreateTransactionException("Could not open JPA EntityManager for transaction", ex);
431431
}

spring-tx/src/main/java/org/springframework/jca/cci/connection/CciLocalTransactionManager.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,8 +29,8 @@
2929
import org.springframework.transaction.TransactionSystemException;
3030
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
3131
import org.springframework.transaction.support.DefaultTransactionStatus;
32-
import org.springframework.transaction.support.TransactionSynchronizationManager;
3332
import org.springframework.transaction.support.ResourceTransactionManager;
33+
import org.springframework.transaction.support.TransactionSynchronizationManager;
3434

3535
/**
3636
* {@link org.springframework.transaction.PlatformTransactionManager} implementation
@@ -141,7 +141,6 @@ protected boolean isExistingTransaction(Object transaction) {
141141
@Override
142142
protected void doBegin(Object transaction, TransactionDefinition definition) {
143143
CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
144-
145144
Connection con = null;
146145

147146
try {
@@ -169,7 +168,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
169168
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
170169
throw new CannotCreateTransactionException("Could not begin local CCI transaction", ex);
171170
}
172-
catch (ResourceException ex) {
171+
catch (Throwable ex) {
173172
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory());
174173
throw new TransactionSystemException("Unexpected failure on begin of CCI local transaction", ex);
175174
}

0 commit comments

Comments
 (0)