-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Memory leak when using @Async after upgrading from 5.1 to 5.2 #23571
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
Comments
Hi @arian, Can you possibly reduce this to the smallest application possible that demonstrates the behavior (and provide access to the full example application)? At the very least, it would be helpful to know what kind of components are active in the Without being able to debug it, we don't really have much to go on. Thanks in advance! |
Yes I completely understand! It's difficult to create a reproducible small application for me as I don't really figured out what causes the problem.
Is there an easy way to print a log of this or something? Anyway I'll try to do some more testing after the weekend and see if I can report back! |
Not for the annotations is use; however, it appears that you're using If you're using Spring Boot, you could use the actuator endpoint to get a list of all beans in the
Thanks. |
The problem seems to occur with With Also a heapdump when running without Also commenting out all Checked with 5.2.0.RC2, same result as RC1. |
Thanks for investigating further and providing us the detailed feedback! We'll look into it. |
Tentatively slated for 5.2 GA for further investigation since this appears to be a regression. |
Hi @arian, Since this appears to be a regression, we'd really like to get to the bottom of this before we release Spring Framework 5.2 GA next week. We brainstormed a bit within the team about possible causes for this, but we're really just shooting in the dark without being able to debug a project that reproduces the memory leak. Based on your knowledge that the issue involves the use of If that's not possible, can you please run your test suite against 5.2 M1, 5.2 M2, and 5.2 M3 and let us know for which milestone versions you experience the problem? That would help us at least to pinpoint when the regression was introduced. Thanks in advance! |
@arian, don't worry about the requests in my previous comment. The following test class seems to reproduce the problem, if you limit the max heap size to 64 MB. The test class succeeds unless you uncomment @SpringJUnitConfig
class AsyncTestCase {
@RepeatedTest(1000)
// @DirtiesContext
void test() {
}
@Configuration
@EnableAsync
@Import(AsyncService.class)
static class Config {
}
static class AsyncService {
@Async
void doSomething() {
}
}
} |
@arian, one last question: Which testing framework are you using?
|
Cool, I was just looking into a way to reproduce it! We're still using junit 4 at the moment. |
OK. Thanks for the feedback. |
Same error occurs with JUnit 4: @RunWith(SpringRunner.class)
public class AsyncTestCase {
@Test
@Repeat(1000)
@DirtiesContext
public void test() {
}
@Configuration
@EnableAsync
@Import(AsyncService.class)
static class Config {
}
static class AsyncService {
@Async
void doSomething() {
}
}
} |
@arian, can you confirm that executing your test suite with |
Mystery solved: the newly introduced I've got a fix locally that I'll apply tomorrow to |
With that it seems to work without leaks.
Great! |
While resolving the regression raised in spring-projectsgh-23571, it came to our attention that not all of our ClassFilter and MethodMatcher implementations were properly cacheable with CGLIB generated proxies due to missing (or improper) equals() and hashCode() implementations. Although such deficiencies may not manifest themselves as bugs in Core Spring's default arrangements, these might cause issues in custom arrangements in user applications. This commit addresses this by ensuring that ClassFilter and MethodMatcher implementations properly implement equals() and hashCode(). In addition, missing toString() implementations have been added to improve diagnostics for logging and debugging. Closes spring-projectsgh-23659
While resolving the regression raised in gh-23571, it came to our attention that not all of our ClassFilter and MethodMatcher implementations were properly cacheable with CGLIB generated proxies due to missing (or improper) equals() and hashCode() implementations. Although such deficiencies may not manifest themselves as bugs in Core Spring's default arrangements, these might cause issues in custom arrangements in user applications. This commit addresses this by ensuring that ClassFilter and MethodMatcher implementations properly implement equals() and hashCode(). In addition, missing toString() implementations have been added to improve diagnostics for logging and debugging. Closes gh-23659
Affects: 5.2.0.RC1
In our application I upgraded from spring-framework 5.1.9 to 5.2.0.RC1 and our tests started leaking memory.
Previously it looked like this in VisualVM:
And now it looks like this:
I've made a heapdump to see where the memory is going:
I've seen something similar in our application previously, but that was solved by using
@MockBean
instead of a lot of@ContextConfiguration
with@Configuration
classes inside our test classes to override beans with mocked objects 🤔...The text was updated successfully, but these errors were encountered: