From 9ff8009fe1c048cf5bc73a18617ecd233704ad92 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Thu, 16 Nov 2023 08:12:02 -0500 Subject: [PATCH] Process Spawner: protect against races between TERM and KILL Because a task (usually a test) can simply finish by itself, either before a TERM or between a TERM and a KILL, it's important to protect against the process not existing anymore. File "/Users/runner/work/avocado/avocado/avocado/plugins/spawners/process.py", line 87, in terminate_task runtime_task.spawner_handle.process.kill() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/subprocess.py", line 143, in kill self._transport.kill() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_subprocess.py", line 153, in kill self._check_proc() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_subprocess.py", line 142, in _check_proc raise ProcessLookupError() The following is an exercept from a stacktrace when the situation hits. Signed-off-by: Cleber Rosa --- avocado/plugins/spawners/process.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/avocado/plugins/spawners/process.py b/avocado/plugins/spawners/process.py index 9fbac46188..7dc69004aa 100644 --- a/avocado/plugins/spawners/process.py +++ b/avocado/plugins/spawners/process.py @@ -74,7 +74,10 @@ async def wait_task(runtime_task): # pylint: disable=W0221 await runtime_task.spawner_handle.wait_task async def terminate_task(self, runtime_task): - runtime_task.spawner_handle.process.terminate() + try: + runtime_task.spawner_handle.process.terminate() + except ProcessLookupError: + return True soft_interval = self.config.get( "runner.task.interval.from_soft_to_hard_termination" ) @@ -84,7 +87,10 @@ async def terminate_task(self, runtime_task): runtime_task.spawner_handle.process.wait(), soft_interval ) except asyncio.TimeoutError: - runtime_task.spawner_handle.process.kill() + try: + runtime_task.spawner_handle.process.kill() + except ProcessLookupError: + return True hard_interval = self.config.get( "runner.task.interval.from_hard_termination_to_verification" )