-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
From spootsy.ootsy on September 26, 2012 22:48:16
We've been using Guice in our projects for a while now, and it's been great. There's one feature/bug that is a reliable source of bugs for us, though.
When using the JpaPersistService, if you attempt to access an EntityManager outside of an active UnitOfWork, Guice will automatically start one for you. However, as Guice does not (and cannot) know when to end this UnitOfWork, it never does.
Result? The offending thread will be stuck with the same EntityManager throughout the life of the application. This is a bad state for the application to run in, and ours inevitably exhaust the available memory after a while and crash.
The real killer here is that it's not at all obvious when you've made this mistake. The only real tip-off is that you're getting inconsistent data from your database between different threads (due to the EMs first-level cache) or that the applications memory consumption keeps on growing.
I think it would be much better behaviour to simply throw an exception if an attempt is made to access an EntityManager instance outside of an active UnitOfWork. This lets the developer know that they've made a mistake and are attempting to access the database outside of a valid scope. Steps to reproduce: 1. 'mvn test' on the supplied maven project (assumes postgres running on localhost:5432 with DB/user/pass 'test')
Binary attachments: guice_persist_same_em.zip
Original issue: http://code.google.com/p/google-guice/issues/detail?id=730