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

Memory Leak for Tests Using @DirtiesContext Annotation #10535

Closed
jonroler opened this issue Mar 16, 2017 · 0 comments
Closed

Memory Leak for Tests Using @DirtiesContext Annotation #10535

jonroler opened this issue Mar 16, 2017 · 0 comments
Assignees
Milestone

Comments

@jonroler
Copy link

jonroler commented Mar 16, 2017

Steps to Reproduce

  1. git clone https://github.com/jonroler/grails-dirties-context-mem-leak.git
  2. cd grails-dirties-context-mem-leak
  3. ./grailsw test-app -integration

Expected Behaviour

The size of the grails.util.Holders.servletContexts.instances map should remain the same after the execution of a test annotated with @DirtiesContext. According to the grails docs, grails should support the @DirtiesContext annotation: http://docs.grails.org/latest/guide/testing.html#integrationTesting.

Actual Behaviour

The size of grails.util.Holders.servletContexts.instances increases by one after the execution of a test annotated with @DirtiesContext (see the standard output generated by the test run). This appears to be a memory leak. It is a pretty serious memory leak because it appears to leak a copy of the spring application context, hibernate session factory, etc. for every single test method with the @DirtiesContext annotation. Most of our tests do not use this annotation, but we have enough of them that this leak is causing us to not be able to run our integration tests with a 4GB heap when a 1GB heap should normally be sufficient (and was sufficient in grails 2.5.1--we're attempting to upgrade to grails 3 right now, but this bug is blocking us).

The bug appears to be when grails tries to clean up entries in the grails.util.Holders.servletContexts.instances map, it is failing to do so since different thread context classloaders are being used when the map entries are added and when they are removed. Since the key of the map is based on the thread context classloader, see grails.util.Holder.getClassLoaderId(), the removal fails to remove anything since it computes the wrong key to remove from the map.

Note that I'm not sure whether the hibernate session factories are leaking through the grails.util.Holders.servletContexts.instances map or not. They do appear to be leaking, though, and they appear to leak in exactly the same way (the @DirtiesContext annotation), so that leak needs to be fixed as well (if it is a different leak).

Environment Information

Example Application

https://github.com/jonroler/grails-dirties-context-mem-leak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants