Re: how to get rid of BTreeContainer as global variable
Jason Madden <[email protected]>
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
> On Sep 7, 2016, at 06:56, Sanjay Rao <[email protected]> wrote: > > Hi, > > I am using multiple objects of BTreeContainer (zope.app.container.btree.BTreeContainer) to store global mapping data in my application. (Note that the code has moved to simply zope.container.btree.BTreeContainer. The zope.app.container.btree name is simply a backwards compatibility alias, new code should use zope.container.btree directly.) > Now with new ZODB(4.4) and ZEO(4.3), my application randomly throws following Error > > ConnectionStateError: Shouldn't load state for baton.tpd.variants.VariantsRegistry 0x043155 when the connection is closed > > > If I replace BTreeContainer with OOBTree, Is it a safe bet to get rid of this problem ? No. They're both persistent object types. This problem occurs when using *any* persistent object outside the scope of its connection. This was discussed in some detail in an email on Aug 24: > Note, however, that that connection is not necessarily safe to use or associated with the current thread. If you have a bug in your code that allows a persistent object to leak between threads or outlive a transaction boundary when the connection is closed, you can run into trouble. A faulty cache, for example, can produce this situation, leaving you with ConnectionStateErrors: > > py>> import ZODB, ZODB.DemoStorage, persistent, transaction > py>> db = ZODB.DB(ZODB.DemoStorage.DemoStorage()) > py>> conn = db.open() > py>> plist = persistent.list.PersistentList() > py>> conn.root()['key'] = plist > # Note that there is no connection yet > py>> plist._p_jar > # After commit we have a connection > py>> transaction.commit() > py>> plist._p_jar > <Connection at 10728bf30> > # But we still have it after the connection is closed > py>> conn.close() > py>> plist._p_jar > <Connection at 10728bf30> > # And it is useless > py>> plist.thing > Traceback (most recent call last): > ... > ConnectionStateError: Shouldn't load state for persistent.list.PersistentList 0x316490b7e11981b6 when the connection is closed > py>> plist._p_jar.root() > Traceback (most recent call last): > ... > ConnectionStateError: The database connection is closed > > So I guess I'm just saying, be careful about the lifetime of your persistent objects. Other than a faulty cache, trying to use persistent objects as module globals, or passing them up through WSGI middleware or pyramid tweens that are "above" the connection/transaction management can cause this type of error. I think you'll find that the error isn't really "random," there's a specific misuse of objects that gets you there. Jason -- You received this message because you are subscribed to the Google Groups "zodb" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.