Skip to content

Commit

Permalink
Process Spawner: protect against races between TERM and KILL
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
clebergnu committed Nov 16, 2023
1 parent 53c4418 commit 9ff8009
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions avocado/plugins/spawners/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand Down

0 comments on commit 9ff8009

Please sign in to comment.