Skip to content

Transaction manager bean in TransactionInterceptor retained after JUnit test class completes [SPR-14511] #19080

@spring-projects-issues

Description

@spring-projects-issues

Will Darby opened SPR-14511 and commented

I am migrating from Spring Framework 3.2.15 to 4.3.1. I have a JUnit Test Suite with ~800 tests, and started running into out of heap memory errors after changing to 4.3.1. I compared .hprof dumps to the 3.2.15 version and the difference appears to be that CglibAopProxy$ProxyCallbackFitler are created for each test class with @Transactional annotation (or @Transactional @Test methods). This then retains TransactionInterceptor Advice, which eventually references the HibernateTransactionManager.

The CglibAopProxy$ProxyCallbackFitler is referenced by the CGLIB$CALLBACK_FILTER field of the CGLIB enhanced test class, which is referenced by the AppClassLoader.

These ProxyCallbackFilters were not retained in Spring 3.2.15, thus it appears to be an introduced leak.

Below are 2 HPROF dumps. The first shows the reference to ProxyCallbackFilter from AppClassLoader. The second shows the reference to HibernateTransactionManager from ProxyCallbackFilter.

Class Name                                                                                                                                     | Shallow Heap | Retained Heap
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
org.springframework.aop.framework.CglibAopProxy$ProxyCallbackFilter @ 0xee643418                                                               |           24 |     3,199,752
|- referent org.springframework.cglib.core.WeakCacheKey @ 0xedcec6f8                                                                           |           32 |            32
|- CGLIB$CALLBACK_FILTER class test.com.leeriver.trading.pjm.eDataFeed.ConstraintPriceUpdateTest2$$EnhancerBySpringCGLIB$$ac9e61d9 @ 0xee6427b0|          128 |         3,088
|  |- [11536] java.lang.Object[20480] @ 0xe203fe38                                                                                             |       81,936 |   215,507,136
|  |  '- elementData java.util.Vector @ 0xe0153e20                                                                                             |           32 |   215,507,168
|  |     '- classes sun.misc.Launcher$AppClassLoader @ 0xe00d5700 Native Stack                                                                 |           88 |   216,679,856
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Class Name                                                                                                                            | Shallow Heap | Retained Heap
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
org.springframework.aop.framework.CglibAopProxy$ProxyCallbackFilter @ 0xee643418                                                      |           24 |     3,199,752
|- <class> class org.springframework.aop.framework.CglibAopProxy$ProxyCallbackFilter @ 0xe1bbb878                                     |            0 |             0
|- advised org.springframework.aop.framework.AdvisedSupport @ 0xee643430                                                              |           48 |     3,199,728
|  |- <class> class org.springframework.aop.framework.AdvisedSupport @ 0xe0e21850                                                     |           16 |            16
|  |- targetSource org.springframework.aop.target.EmptyTargetSource @ 0xee643460                                                      |           24 |            24
|  |- advisorChainFactory org.springframework.aop.framework.DefaultAdvisorChainFactory @ 0xee643478                                   |           16 |            16
|  |- methodCache java.util.concurrent.ConcurrentHashMap @ 0xee643488                                                                 |           64 |         1,568
|  |- interfaces java.util.ArrayList @ 0xee643e88                                                                                     |           24 |            24
|  |- advisors java.util.LinkedList @ 0xee643ea0                                                                                      |           32 |            56
|  |- advisorArray org.springframework.aop.Advisor[1] @ 0xee643ed8                                                                    |           24 |            24
|  |  |- <class> class org.springframework.aop.Advisor[] @ 0xe0e01070                                                                 |            0 |             0
|  |  |- [0] org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor @ 0xee5cc2f0                    |           40 |            64
|  |  |  |- <class> class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor @ 0xe0de84c8       |            0 |             0
|  |  |  |- order java.lang.Integer @ 0xe00cc4d0  10                                                                                  |           16 |            16
|  |  |  |- beanFactory org.springframework.beans.factory.support.DefaultListableBeanFactory @ 0xee5907a8                             |          208 |       202,624
|  |  |  |- adviceMonitor java.util.concurrent.ConcurrentHashMap @ 0xee590ad8                                                         |           64 |         2,128
|  |  |  |- adviceBeanName java.lang.String @ 0xee592e08  org.springframework.transaction.interceptor.TransactionInterceptor#0        |           24 |           176
|  |  |  |- transactionAttributeSource org.springframework.transaction.annotation.AnnotationTransactionAttributeSource @ 0xee5b4898   |           32 |       206,552
|  |  |  |- pointcut org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor$1 @ 0xee5cc318          |           24 |            24
|  |  |  |- advice org.springframework.transaction.interceptor.TransactionInterceptor @ 0xee6438d8                                    |           40 |     2,784,376
|  |  |  |  |- <class> class org.springframework.transaction.interceptor.TransactionInterceptor @ 0xe0de9ed0                          |            0 |             0
|  |  |  |  |- logger org.apache.commons.logging.impl.SLF4JLocationAwareLog @ 0xe137ddf0                                              |           24 |            24
|  |  |  |  |- transactionManagerBeanName java.lang.String @ 0xee2f4da8  transactionManager                                           |           24 |            80
|  |  |  |  |- beanFactory org.springframework.beans.factory.support.DefaultListableBeanFactory @ 0xee5907a8                          |          208 |       202,624
|  |  |  |  |- transactionAttributeSource org.springframework.transaction.annotation.AnnotationTransactionAttributeSource @ 0xee5b4898|           32 |       206,552
|  |  |  |  |- DEFAULT_TRANSACTION_MANAGER_KEY java.lang.Object @ 0xee643900                                                          |           16 |            16
|  |  |  |  |- transactionManagerCache java.util.concurrent.ConcurrentHashMap @ 0xee643910                                            |           64 |     2,784,320
|  |  |  |  |  |- <class> class java.util.concurrent.ConcurrentHashMap @ 0xe0002928 System Class                                      |          136 |           616
|  |  |  |  |  |- table java.util.concurrent.ConcurrentHashMap$Node[16] @ 0xee643950                                                  |           80 |     2,784,256
|  |  |  |  |  |  |- <class> class java.util.concurrent.ConcurrentHashMap$Node[] @ 0xe00c82d8                                         |            0 |             0
|  |  |  |  |  |  |- [10] java.util.concurrent.ConcurrentHashMap$Node @ 0xee6439a0                                                    |           32 |     2,784,176
|  |  |  |  |  |  |  |- <class> class java.util.concurrent.ConcurrentHashMap$Node @ 0xe0253a50 System Class                           |            0 |             0
|  |  |  |  |  |  |  |- key java.lang.String @ 0xee2f4da8  transactionManager                                                         |           24 |            80
|  |  |  |  |  |  |  |- val org.springframework.orm.hibernate5.HibernateTransactionManager @ 0xee6439c0                               |           56 |     2,784,144
---------------------------------------------------------------------------------------------------------------------------------------------------------------------


Affects: 4.3.1

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions