Explorar o código

fix Repository._active_txn state when lock upgrade fails

Thomas Waldmann %!s(int64=10) %!d(string=hai) anos
pai
achega
3b744d2ee8
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      attic/repository.py

+ 8 - 1
attic/repository.py

@@ -138,7 +138,14 @@ class Repository(object):
 
     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: