update_manager: use SIGKILL to cancel git processes

It is necessary to guarantee that the process dies when cancelled.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2021-03-29 07:35:18 -04:00
parent 9b0c9810a4
commit c0389fbf3f
1 changed files with 8 additions and 6 deletions

View File

@ -356,20 +356,21 @@ class CommandHelper:
break break
async def run_cmd(self, cmd, timeout=20., notify=False, async def run_cmd(self, cmd, timeout=20., notify=False,
retries=1, env=None, cwd=None): retries=1, env=None, cwd=None, sig_idx=1):
cb = self.notify_update_response if notify else None cb = self.notify_update_response if notify else None
scmd = self.build_shell_command(cmd, callback=cb, env=env, cwd=cwd) scmd = self.build_shell_command(cmd, callback=cb, env=env, cwd=cwd)
while retries: while retries:
if await scmd.run(timeout=timeout): if await scmd.run(timeout=timeout, sig_idx=sig_idx):
break break
retries -= 1 retries -= 1
if not retries: if not retries:
raise self.server.error("Shell Command Error") raise self.server.error("Shell Command Error")
async def run_cmd_with_response(self, cmd, timeout=20., retries=5, async def run_cmd_with_response(self, cmd, timeout=20., retries=5,
env=None, cwd=None): env=None, cwd=None, sig_idx=1):
scmd = self.build_shell_command(cmd, None, env=env, cwd=cwd) scmd = self.build_shell_command(cmd, None, env=env, cwd=cwd)
result = await scmd.run_with_response(timeout, retries) result = await scmd.run_with_response(
timeout, retries, sig_idx=sig_idx)
return result return result
async def github_api_request(self, url, etag=None, is_init=False): async def github_api_request(self, url, etag=None, is_init=False):
@ -1254,14 +1255,15 @@ class GitRepo:
else: else:
# Request has timed out with no input, terminate it # Request has timed out with no input, terminate it
logging.debug(f"Git Repo {self.alias}: Fetch/Pull timed out") logging.debug(f"Git Repo {self.alias}: Fetch/Pull timed out")
await scmd.cancel() # Cancel with SIGKILL
await scmd.cancel(2)
async def _run_git_cmd(self, git_args, timeout=20., retries=5, async def _run_git_cmd(self, git_args, timeout=20., retries=5,
env=None): env=None):
try: try:
return await self.cmd_helper.run_cmd_with_response( return await self.cmd_helper.run_cmd_with_response(
f"git -C {self.git_path} {git_args}", f"git -C {self.git_path} {git_args}",
timeout=timeout, retries=retries, env=env) timeout=timeout, retries=retries, env=env, sig_idx=2)
except self.cmd_helper.scmd_error as e: except self.cmd_helper.scmd_error as e:
stdout = e.stdout.decode().strip() stdout = e.stdout.decode().strip()
stderr = e.stderr.decode().strip() stderr = e.stderr.decode().strip()