diff options
author | Zac Medico <zmedico@gentoo.org> | 2020-03-01 10:28:21 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2020-03-01 10:36:04 -0800 |
commit | 1681309f252a4e91d7256b895a9af26ef82a9b30 (patch) | |
tree | 246698e8e89e6b8127d64e7a8a95e8cd509c7fc4 /lib | |
parent | Updates for portage-2.3.90 release (diff) | |
download | portage-1681309f252a4e91d7256b895a9af26ef82a9b30.tar.gz portage-1681309f252a4e91d7256b895a9af26ef82a9b30.tar.bz2 portage-1681309f252a4e91d7256b895a9af26ef82a9b30.zip |
_BinpkgFetcherProcess: fix async_lock event loop recursion (bug 711178)
Make the async_lock method use the AsynchronousLock async_start
method in order to avoid event loop recursion.
Fixes: 5c40c3e7e ("SpawnProcess: use async_start method (bug 709746)")
Bug: https://bugs.gentoo.org/711178
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_emerge/BinpkgFetcher.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/_emerge/BinpkgFetcher.py b/lib/_emerge/BinpkgFetcher.py index 640eead91..e788cb05d 100644 --- a/lib/_emerge/BinpkgFetcher.py +++ b/lib/_emerge/BinpkgFetcher.py @@ -16,6 +16,7 @@ import portage from portage import os from portage.util._async.AsyncTaskFuture import AsyncTaskFuture from portage.util._pty import _create_pty_or_pipe +from portage.util.futures import asyncio from portage.util.futures.compat_coroutine import coroutine if sys.hexversion >= 0x3000000: @@ -205,6 +206,7 @@ class _BinpkgFetcherProcess(SpawnProcess): except OSError: pass + @coroutine def async_lock(self): """ This raises an AlreadyLocked exception if lock() is called @@ -215,22 +217,22 @@ class _BinpkgFetcherProcess(SpawnProcess): if self._lock_obj is not None: raise self.AlreadyLocked((self._lock_obj,)) - result = self.scheduler.create_future() - - def acquired_lock(async_lock): - if async_lock.wait() == os.EX_OK: - self.locked = True - result.set_result(None) - else: - result.set_exception(AssertionError( - "AsynchronousLock failed with returncode %s" - % (async_lock.returncode,))) - - self._lock_obj = AsynchronousLock(path=self.pkg_path, + async_lock = self._lock_obj = AsynchronousLock(path=self.pkg_path, scheduler=self.scheduler) - self._lock_obj.addExitListener(acquired_lock) - self._lock_obj.start() - return result + try: + yield async_lock.async_start() + yield async_lock.async_wait() + except asyncio.CancelledError: + if async_lock.poll() is None: + async_lock.cancel() + raise + + if async_lock.returncode != os.EX_OK: + raise AssertionError( + "AsynchronousLock failed with returncode %s" + % (async_lock.returncode,)) + + self.locked = True class AlreadyLocked(portage.exception.PortageException): pass |