aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2020-08-09 00:38:18 -0700
committerZac Medico <zmedico@gentoo.org>2020-08-09 00:39:10 -0700
commita163adec05afba127dfb18529761557bd30655ae (patch)
tree708ee913a8ce2176bea5a9c40f648ea899a7ada0
parentUpdates for portage-3.0.2 release (diff)
downloadportage-a163adec05afba127dfb18529761557bd30655ae.tar.gz
portage-a163adec05afba127dfb18529761557bd30655ae.tar.bz2
portage-a163adec05afba127dfb18529761557bd30655ae.zip
SpawnProcess: fix _cancel to cleanup PipeLogger quickly
Cleanup PipeLogger as quickly as possible, in order to prevent access to unclosed logs. Bug: https://bugs.gentoo.org/711174 Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/_emerge/SpawnProcess.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/_emerge/SpawnProcess.py b/lib/_emerge/SpawnProcess.py
index 91f5ed1a8..cea16df27 100644
--- a/lib/_emerge/SpawnProcess.py
+++ b/lib/_emerge/SpawnProcess.py
@@ -2,6 +2,7 @@
# Distributed under the terms of the GNU General Public License v2
import errno
+import functools
import logging
import signal
import sys
@@ -32,7 +33,7 @@ class SpawnProcess(SubProcess):
"unshare_ipc", "unshare_mount", "unshare_pid", "unshare_net")
__slots__ = ("args", "log_filter_file") + \
- _spawn_kwarg_names + ("_main_task", "_selinux_type",)
+ _spawn_kwarg_names + ("_main_task", "_main_task_cancel", "_selinux_type",)
# Max number of attempts to kill the processes listed in cgroup.procs,
# given that processes may fork before they can be killed.
@@ -138,6 +139,7 @@ class SpawnProcess(SubProcess):
pipe_logger.start()
self._registered = True
+ self._main_task_cancel = functools.partial(self._main_cancel, build_logger, pipe_logger)
self._main_task = asyncio.ensure_future(self._main(build_logger, pipe_logger), loop=self.scheduler)
self._main_task.add_done_callback(self._main_exit)
@@ -149,14 +151,18 @@ class SpawnProcess(SubProcess):
if build_logger.poll() is None:
yield build_logger.async_wait()
except asyncio.CancelledError:
- if pipe_logger.poll() is None:
- pipe_logger.cancel()
- if build_logger.poll() is None:
- build_logger.cancel()
+ self._main_cancel(build_logger, pipe_logger)
raise
+ def _main_cancel(self, build_logger, pipe_logger):
+ if pipe_logger.poll() is None:
+ pipe_logger.cancel()
+ if build_logger.poll() is None:
+ build_logger.cancel()
+
def _main_exit(self, main_task):
self._main_task = None
+ self._main_task_cancel = None
try:
main_task.result()
except asyncio.CancelledError:
@@ -205,7 +211,11 @@ class SpawnProcess(SubProcess):
def _cancel(self):
if self._main_task is not None:
- self._main_task.done() or self._main_task.cancel()
+ if not self._main_task.done():
+ if self._main_task_cancel is not None:
+ self._main_task_cancel()
+ self._main_task_cancel = None
+ self._main_task.cancel()
SubProcess._cancel(self)
self._cgroup_cleanup()