Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: scoped beans being cached too aggressively [SPR-9627] #14261

spring-projects-issues opened this issue Jul 24, 2012 · 2 comments
in: core type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Jul 24, 2012

Samuel Bernet opened SPR-9627 and commented

The bugfix #13814 "Scoped-proxy memory leak w/ @Resource injection" leads to bean instances being cached too eagerly in CommonAnnotationBeanPostProcessor. Besides the (desired) caching of AOP scoped-proxies to prevent the memory leak the current code also caches custom scoped bean instances that should not be cached. This happens for example if client code uses AutowireCapableBeanFactory#autowireBean(Object) to inject dependencies (annotation-based) into a manually created bean. In this case no AOP proxies are involved but the cached instances are still used. The underlying scope is never consulted and can thus never signalize that a new instance is to be created and injected because the context of the scope (e.g. request, session) is different from the first call which resulted in the cached instance.

I attached a Test-Case (JUnit 4 Test, requires JUnit and Spring to run). The test-case illustrates the breaking change:

  • Runs fine with Spring version 3.1.1 and older (tested with 3.0.5)
  • Fails with Spring version 3.1.2 and 3.2.M1
  • The defect was introduced in the bugfix for #13814 in version 3.2.M1 with commit f779c19
  • The defect was back-ported to version 3.1.2 with #14000

I understand this calling pattern is not very common but nevertheless the affected API is public and our framework relies on this to provide service beans to instances of "visual" classes (a visual models a single page in a web application). This basically renders custom scoped beans (also being used heavily) unusable for us in releases > 3.1.1, thus my classification as "major".

Best regards
Samuel Bernet
MSc ETH Software Engineering

Affects: 3.1.2, 3.2 M1


Issue Links:

  • #14318 @Resource injection regression with scope prototype ("is duplicated by")
  • #13814 Scoped-proxy memory leak w/ @Resource injection
  • #14214 Injecting prototypes into tests using @Resource appears to be broken
  • #14000 Backport "Scoped-proxy memory leak w/ @Resource injection"
  • #14485 @Resource injection of singleton in prototype using AnnotationConfigApplicationContext is not thread-safe

Referenced from: commits 04af54a, 26ee0c4, 68c5f20, 1971870

1 votes, 5 watchers

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 14, 2012

Wouter Coekaerts commented

Also see the test case attached to #14318: it shows it happens for prototype scoped beans injected with @Resource, but not with @Autowired.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 16, 2012

Chris Beams commented

See also the reproduction project attached to duplicate issue #14318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: bug
None yet

No branches or pull requests

2 participants