diff options
author | Devaev Maxim <[email protected]> | 2018-07-17 00:10:38 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-07-17 00:10:38 +0300 |
commit | caf7f4c99bce4533e7fc1b9f7aeaaf605baf819c (patch) | |
tree | cf93836ce4df194b1c640853f8ca6181eb52d79c | |
parent | ddabd32807cf6a693127a31532bb9651060a778f (diff) |
fixed msd deadlock
-rw-r--r-- | kvmd/kvmd/msd.py | 13 |
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 |