From 3b744d2ee8b80c5a0c818443db23fd36e0ae1162 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 9 Mar 2015 20:45:31 +0100 Subject: [PATCH] fix Repository._active_txn state when lock upgrade fails --- attic/repository.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/attic/repository.py b/attic/repository.py index eed85dc43..096d494f8 100644 --- a/attic/repository.py +++ b/attic/repository.py @@ -138,7 +138,14 @@ def open_index(self, transaction_id): def prepare_txn(self, transaction_id, do_cleanup=True): self._active_txn = True - self.lock.upgrade() + try: + self.lock.upgrade() + except UpgradableLock.WriteLockFailed: + # if upgrading the lock to exclusive fails, we do not have an + # active transaction. this is important for "serve" mode, where + # the repository instance lives on - even if exceptions happened. + self._active_txn = False + raise if not self.index: self.index = self.open_index(transaction_id) if transaction_id is None: