Summary:
Issues with memory leaks when using multiple guice instances in succession
Scenario:
Bring up a guice container (instance1) and allow the application to run with
instance1, after some time bring up new guice container (guice2) and if
successful atomically switch the application to instance2. If instance2
fails to start for any reason then keep using instance1. Once the switch
is complete then let guice1 be garbage collected. After the application
run for a while with intance2 restart the whole process and bring up instance4,
then instance5 ...
Problem:
Guice filter always contains a reference to any new guice instance. In
this case the guice filter is included in the guice container instance so each
time guice starts a new guice fitler gets created and used correctly since the
application determines which guice filter to submit the request to. In
the case that instance2 failed to start then instance2 should be garbage
collected and not stored in guice filter.
Workaround:
1. use reflection to call GuiceFilter.reset This is a static method and clears
the unneeded reference. The guice filter still has reference to the
correct guice instance via the variable injectedPipeline
Source code of workaround:
Class guiceFilterClass = GuiceFilter.class;
Method[] methods = guiceFilterClass.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals("reset")) {
method.setAccessible(true);
method.invoke(null);
break;
}
}
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/d3c6677a-1488-4b22-9d98-d7c4e238c78f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.