update_manager: remove redundant locks

All requests to update, refresh, recover, or reinstall must acquire
the command lock. Given that the individual Deployment implementations
are not (and should not be) called from outside of a request the locks they
use to prevent unwanted re-entry are redundant, confusing, and could
potential result in a deadlock if used improperly.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-01-23 08:31:56 -05:00 committed by Eric Callahan
parent 4d473969db
commit b1a232efce
2 changed files with 101 additions and 133 deletions

View File

@ -783,8 +783,6 @@ class PackageDeploy(BaseDeploy):
storage = self._load_storage() storage = self._load_storage()
self.use_packagekit = config.getboolean("enable_packagekit", True) self.use_packagekit = config.getboolean("enable_packagekit", True)
self.available_packages: List[str] = storage.get('packages', []) self.available_packages: List[str] = storage.get('packages', [])
self.refresh_evt: Optional[asyncio.Event] = None
self.mutex: asyncio.Lock = asyncio.Lock()
async def initialize(self) -> None: async def initialize(self) -> None:
provider: BasePackageProvider provider: BasePackageProvider
@ -833,11 +831,6 @@ class PackageDeploy(BaseDeploy):
return provider return provider
async def refresh(self) -> None: async def refresh(self) -> None:
if self.refresh_evt is not None:
self.refresh_evt.wait()
return
async with self.mutex:
self.refresh_evt = asyncio.Event()
try: try:
# Do not force a refresh until the server has started # Do not force a refresh until the server has started
if self.server.is_running(): if self.server.is_running():
@ -849,8 +842,6 @@ class PackageDeploy(BaseDeploy):
f"\n{pkg_msg}") f"\n{pkg_msg}")
except Exception: except Exception:
logging.exception("Error Refreshing System Packages") logging.exception("Error Refreshing System Packages")
self.refresh_evt.set()
self.refresh_evt = None
# Update Persistent Storage # Update Persistent Storage
self._save_state() self._save_state()
@ -860,7 +851,6 @@ class PackageDeploy(BaseDeploy):
return storage return storage
async def update(self) -> bool: async def update(self) -> bool:
async with self.mutex:
if not self.available_packages: if not self.available_packages:
return False return False
self.cmd_helper.notify_update_response("Updating packages...") self.cmd_helper.notify_update_response("Updating packages...")
@ -1304,8 +1294,6 @@ class WebClientDeploy(BaseDeploy):
dl_info: List[Any] = storage.get('dl_info', ["?", "?", 0]) dl_info: List[Any] = storage.get('dl_info', ["?", "?", 0])
self.dl_info: Tuple[str, str, int] = cast( self.dl_info: Tuple[str, str, int] = cast(
Tuple[str, str, int], tuple(dl_info)) Tuple[str, str, int], tuple(dl_info))
self.refresh_evt: Optional[asyncio.Event] = None
self.mutex: asyncio.Lock = asyncio.Lock()
logging.info(f"\nInitializing Client Updater: '{self.name}'," logging.info(f"\nInitializing Client Updater: '{self.name}',"
f"\nChannel: {self.channel}" f"\nChannel: {self.channel}"
f"\npath: {self.path}") f"\npath: {self.path}")
@ -1320,18 +1308,11 @@ class WebClientDeploy(BaseDeploy):
self.version = "?" self.version = "?"
async def refresh(self) -> None: async def refresh(self) -> None:
if self.refresh_evt is not None:
self.refresh_evt.wait()
return
async with self.mutex:
self.refresh_evt = asyncio.Event()
try: try:
await self._get_local_version() await self._get_local_version()
await self._get_remote_version() await self._get_remote_version()
except Exception: except Exception:
logging.exception("Error Refreshing Client") logging.exception("Error Refreshing Client")
self.refresh_evt.set()
self.refresh_evt = None
self._save_state() self._save_state()
async def _get_remote_version(self) -> None: async def _get_remote_version(self) -> None:
@ -1375,7 +1356,6 @@ class WebClientDeploy(BaseDeploy):
return storage return storage
async def update(self) -> bool: async def update(self) -> bool:
async with self.mutex:
if self.remote_version == "?": if self.remote_version == "?":
await self._get_remote_version() await self._get_remote_version()
if self.remote_version == "?": if self.remote_version == "?":

View File

@ -5,7 +5,6 @@
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
from __future__ import annotations from __future__ import annotations
import asyncio
import os import os
import pathlib import pathlib
import json import json
@ -74,8 +73,6 @@ class ZipDeploy(AppDeploy):
self.package_list: List[str] = [] self.package_list: List[str] = []
self.python_pkg_list: List[str] = [] self.python_pkg_list: List[str] = []
self.release_download_info: Tuple[str, str, int] = ("?", "?", 0) self.release_download_info: Tuple[str, str, int] = ("?", "?", 0)
self.mutex: asyncio.Lock = asyncio.Lock()
self.refresh_event: Optional[asyncio.Event] = None
@staticmethod @staticmethod
async def from_application(app: AppDeploy) -> ZipDeploy: async def from_application(app: AppDeploy) -> ZipDeploy:
@ -125,18 +122,11 @@ class ZipDeploy(AppDeploy):
return tag_version return tag_version
async def refresh(self) -> None: async def refresh(self) -> None:
if self.refresh_event is not None:
await self.refresh_event.wait()
return
async with self.mutex:
self.refresh_event = asyncio.Event()
try: try:
await self._update_repo_state() await self._update_repo_state()
except Exception: except Exception:
self.verified = False self.verified = False
self.log_exc("Error refreshing application state") self.log_exc("Error refreshing application state")
self.refresh_event.set()
self.refresh_event = None
async def _update_repo_state(self) -> None: async def _update_repo_state(self) -> None:
self.errors = [] self.errors = []
@ -372,7 +362,6 @@ class ZipDeploy(AppDeploy):
zf.extractall(self.path) zf.extractall(self.path)
async def update(self, force_dep_update: bool = False) -> bool: async def update(self, force_dep_update: bool = False) -> bool:
async with self.mutex:
if not self._is_valid: if not self._is_valid:
raise self.log_exc("Update aborted, repo not valid", False) raise self.log_exc("Update aborted, repo not valid", False)
if self.short_version == self.latest_version: if self.short_version == self.latest_version:
@ -404,7 +393,6 @@ class ZipDeploy(AppDeploy):
hard: bool = False, hard: bool = False,
force_dep_update: bool = False force_dep_update: bool = False
) -> None: ) -> None:
async with self.mutex:
url = f"https://api.github.com/repos/{self.host_repo}/releases" url = f"https://api.github.com/repos/{self.host_repo}/releases"
releases = await self._fetch_github_releases(url) releases = await self._fetch_github_releases(url)
await self._process_latest_release(releases[1]) await self._process_latest_release(releases[1])