You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Steps to Reproduce
git clone https://github.com/jonroler/grails-dirties-context-mem-leak.git
cd grails-dirties-context-mem-leak
./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, seegrails.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
The text was updated successfully, but these errors were encountered: