Skip to content

Commit

Permalink
_BinpkgFetcherProcess: fix async_lock event loop recursion (bug 711178)
Browse files Browse the repository at this point in the history
Make the async_lock method use the AsynchronousLock async_start
method in order to avoid event loop recursion.

Fixes: 5c40c3e ("SpawnProcess: use async_start method (bug 709746)")
Bug: https://bugs.gentoo.org/711178
Signed-off-by: Zac Medico <zmedico@gentoo.org>
  • Loading branch information
zmedico committed Mar 1, 2020
1 parent 2317403 commit 1681309
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/_emerge/BinpkgFetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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:
Expand Down Expand Up @@ -205,6 +206,7 @@ def sync_timestamp(self):
except OSError:
pass

@coroutine
def async_lock(self):
"""
This raises an AlreadyLocked exception if lock() is called
Expand All @@ -215,22 +217,22 @@ def async_lock(self):
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
Expand Down

0 comments on commit 1681309

Please sign in to comment.