From 760e22a90ed028af035fc1a3407e6e6653398f85 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Mon, 12 Sep 2016 10:39:57 -0500 Subject: [PATCH] Clear Connection.transaction_manager on close. Fixes #114 --- CHANGES.rst | 5 +++++ src/ZODB/Connection.py | 8 +++++++- src/ZODB/DB.py | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index f4b5a780c..1209c2d4e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,11 @@ - Call _p_resolveConflict() even if a conflicting change doesn't change the state. This reverts to the behaviour of 3.10.3 and older. +- Closing a Connection now reverts its ``transaction_manager`` to + None. This helps prevent errors and release resources when the + ``transaction_manager`` was the (default) thread-local manager. See + `issue 114 `_. + 4.4.3 (2016-08-04) ================== diff --git a/src/ZODB/Connection.py b/src/ZODB/Connection.py index 077f210b1..4d9924ed2 100644 --- a/src/ZODB/Connection.py +++ b/src/ZODB/Connection.py @@ -307,7 +307,9 @@ def close(self, primary=True): self._debug_info = () - if self.opened: + if self.opened and self.transaction_manager is not None: + # transaction_manager could be None if one of the __onCloseCallbacks + # closed the DB already, .e.g, ZODB.connection() does this. self.transaction_manager.unregisterSynch(self) if self._mvcc_storage: @@ -333,6 +335,9 @@ def close(self, primary=True): if am is not None: am.closedConnection(self) + # Drop transaction manager to release resources and help prevent errors + self.transaction_manager = None + def db(self): """Returns a handle to the database this connection belongs to.""" return self._db @@ -1119,6 +1124,7 @@ def _release_resources(self): c._storage.release() c._storage = c._normal_storage = None c._cache = PickleCache(self, 0, 0) + c.transaction_manager = None ########################################################################## # Python protocol diff --git a/src/ZODB/DB.py b/src/ZODB/DB.py index 9aa61be87..463786d68 100644 --- a/src/ZODB/DB.py +++ b/src/ZODB/DB.py @@ -628,7 +628,8 @@ def close(self): @self._connectionMap def _(c): - c.transaction_manager.abort() + if c.transaction_manager is not None: + c.transaction_manager.abort() c.afterCompletion = c.newTransaction = c.close = noop c._release_resources()