Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
DB Connections are never released if an EndRequestEvent subscriber raises an exception #16
We have a Plone platform with a number of ZODB mounts and recently started noticing some significant memory issues with our instances. Each of our instances currently has one zserver-thread, but for some reason multiple DB connections were being created, resulting in memory use going up and up.
Eventually we tracked it down to a bug in collective.linkcheck, which is raising an Exception during an EndRequestEvent subscriber. Although we've stopped using the product for now, Zope should possibly handle this situation better.
The problem is reproducible with a basic event subscriber:
<subscriber for="zope.publisher.interfaces.IEndRequestEvent" handler=".events.test_end_request" />
def test_end_request(event): raise Exception
A BaseRequest "holds" a number of objects, including the DB Connection. When a BaseRequest is closed, the EndRequestEvent is notified and the Request is then cleared, releasing the Connection (allowing it to be closed/released back to the pool) and any other objects that have been held.
If an Exception is raised in an EndRequestEvent subscriber, the Request is never cleared. The DB Connection and other objects are held forever.
The Request should release these objects even if an Exception has been raised.