From 9725c03299fca8c02c07295886a3ff400d4b565a Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 3 Jul 2016 02:58:17 +0200 Subject: [PATCH] close the repo on exit - even if rollback did not work, fixes #1197 --- borg/remote.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/borg/remote.py b/borg/remote.py index 85012382a..26dce53d4 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -189,9 +189,14 @@ class RemoteRepository: return self def __exit__(self, exc_type, exc_val, exc_tb): - if exc_type is not None: - self.rollback() - self.close() + try: + if exc_type is not None: + self.rollback() + finally: + # in any case, we want to cleanly close the repo, even if the + # rollback can not succeed (e.g. because the connection was + # already closed) and raised another exception: + self.close() def borg_cmd(self, args, testing): """return a borg serve command line"""