summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-17 00:10:38 +0300
committerDevaev Maxim <[email protected]>2018-07-17 00:10:38 +0300
commitcaf7f4c99bce4533e7fc1b9f7aeaaf605baf819c (patch)
treecf93836ce4df194b1c640853f8ca6181eb52d79c
parentddabd32807cf6a693127a31532bb9651060a778f (diff)
fixed msd deadlock
-rw-r--r--kvmd/kvmd/msd.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/kvmd/kvmd/msd.py b/kvmd/kvmd/msd.py
index d668d203..988a1c30 100644
--- a/kvmd/kvmd/msd.py
+++ b/kvmd/kvmd/msd.py
@@ -236,11 +236,14 @@ class MassStorageDevice: # pylint: disable=too-many-instance-attributes
@_msd_operated
async def __aenter__(self) -> "MassStorageDevice":
self.__region.enter()
- if not self.__device_info:
- raise MsdIsNotConnectedToKvmError()
- self.__device_file = await aiofiles.open(self.__device_info.path, mode="w+b", buffering=0)
- self.__written = 0
- return self
+ try:
+ if not self.__device_info:
+ raise MsdIsNotConnectedToKvmError()
+ self.__device_file = await aiofiles.open(self.__device_info.path, mode="w+b", buffering=0)
+ self.__written = 0
+ return self
+ finally:
+ self.__region.exit()
async def write_image_info(self, name: str, complete: bool) -> None:
assert self.__device_file