From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1149886-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id A42A2138350
	for <garchives@archives.gentoo.org>; Wed,  4 Mar 2020 10:28:23 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id E44C5E09F7;
	Wed,  4 Mar 2020 10:28:22 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id B25C3E09F7
	for <gentoo-commits@lists.gentoo.org>; Wed,  4 Mar 2020 10:28:22 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 9B06F34F3A0
	for <gentoo-commits@lists.gentoo.org>; Wed,  4 Mar 2020 10:28:21 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id B17AD15D
	for <gentoo-commits@lists.gentoo.org>; Wed,  4 Mar 2020 10:28:19 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <1583315607.459b3535baa416888b546cd1635ae28324259a70.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: lib/_emerge/
X-VCS-Repository: proj/portage
X-VCS-Files: lib/_emerge/SequentialTaskQueue.py
X-VCS-Directories: lib/_emerge/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 459b3535baa416888b546cd1635ae28324259a70
X-VCS-Branch: master
Date: Wed,  4 Mar 2020 10:28:19 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: a0f84b09-25b0-42ba-9fa4-a6130e1d373e
X-Archives-Hash: a52ef003b374c0111640c9d13c99c8f9

commit:     459b3535baa416888b546cd1635ae28324259a70
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Mar  4 08:17:28 2020 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Mar  4 09:53:27 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=459b3535

SequentialTaskQueue: update bool(self) sooner (bug 711322)

Use addExitListener to add a _task_exit callback that will be invoked
as soon as the task exits (before the future's done callback is called).
This is required in order for bool(self) to have an updated value for
Scheduler._schedule to base assumptions upon. Delayed updates to
bool(self) is what caused Scheduler to hang as in bug 711322.

This reverts changes in SequentialTaskQueue task queue exit listener
behavior from commit c7e52d046621, so that only the changes necessary
to support async_start remain.

Fixes: c7e52d046621 ("EbuildPhase: add _async_start coroutine")
Bug: https://bugs.gentoo.org/711322
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/_emerge/SequentialTaskQueue.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lib/_emerge/SequentialTaskQueue.py b/lib/_emerge/SequentialTaskQueue.py
index a4555275f..318bd6c55 100644
--- a/lib/_emerge/SequentialTaskQueue.py
+++ b/lib/_emerge/SequentialTaskQueue.py
@@ -2,7 +2,6 @@
 # Distributed under the terms of the GNU General Public License v2
 
 from collections import deque
-import functools
 import sys
 
 from portage.util.futures import asyncio
@@ -45,7 +44,14 @@ class SequentialTaskQueue(SlotObject):
 				if not cancelled:
 					self.running_tasks.add(task)
 					future = asyncio.ensure_future(self._task_coroutine(task), loop=task.scheduler)
-					future.add_done_callback(functools.partial(self._task_exit, task))
+					future.add_done_callback(lambda future: future.cancelled() or future.result())
+					# This callback will be invoked as soon as the task
+					# exits (before the future's done callback is called),
+					# and this is required in order for bool(self) to have
+					# an updated value for Scheduler._schedule to base
+					# assumptions upon. Delayed updates to bool(self) is
+					# what caused Scheduler to hang as in bug 709746.
+					task.addExitListener(self._task_exit)
 		finally:
 			self._scheduling = False
 
@@ -54,17 +60,13 @@ class SequentialTaskQueue(SlotObject):
 		yield task.async_start()
 		yield task.async_wait()
 
-	def _task_exit(self, task, future):
+	def _task_exit(self, task):
 		"""
 		Since we can always rely on exit listeners being called, the set of
  		running tasks is always pruned automatically and there is never any need
 		to actively prune it.
 		"""
 		self.running_tasks.remove(task)
-		try:
-			future.result()
-		except asyncio.CancelledError:
-			self.clear()
 		if self._task_queue:
 			self.schedule()