Skip to content

Commit

Permalink
Don't manipulate Connection state after it has been returned to the p…
Browse files Browse the repository at this point in the history
…ool.

Doing so leads to race conditions.

In particular, there can be an AttributeError.

See zodb/zodbshootout#26 for details.

(cherry picked from commit f8cf23e)
  • Loading branch information
jamadden authored and jmuchemb committed Feb 2, 2017
1 parent 9861205 commit 465b350
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

- ``persistent`` is no longer required at setup time.
See `issue 119 <https://github.com/zopefoundation/ZODB/issues/119>`_.
- ``Connection.close`` and ``Connection.open`` no longer race on
``self.transaction_manager``, which could lead to
``AttributeError``. This was a bug introduced in 5.0.1. See `issue
142 <https://github.com/zopefoundation/ZODB/pull/143>`_.

4.4.4 (2016-11-27)
==================
Expand Down
15 changes: 10 additions & 5 deletions src/ZODB/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ def close(self, primary=True):
if self._mvcc_storage:
self._storage.sync(force=False)


am = self._db._activity_monitor
if am is not None:
am.closedConnection(self)

# Drop transaction manager to release resources and help prevent errors
self.transaction_manager = None

if primary:
for connection in self.connections.values():
if connection is not self:
Expand All @@ -331,12 +339,9 @@ def close(self, primary=True):
else:
self.opened = None

am = self._db._activity_monitor
if am is not None:
am.closedConnection(self)
# We may have been reused by another thread at this point so
# we can't manipulate or check the state of `self` any more.

# 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."""
Expand Down

0 comments on commit 465b350

Please sign in to comment.