From 472f08686264f127c4cb79125f25b210476697d1 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Mon, 18 May 2015 10:18:36 -0400 Subject: [PATCH] Fix an issue where a well timed cancel could try to cancel a job right after it has finished causing an error. --- awx/main/tasks.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 93d960aa58..b87eeb99f4 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -393,11 +393,12 @@ class BaseTask(Task): # Refresh model instance from the database (to check cancel flag). instance = self.update_model(instance.pk) if instance.cancel_flag: - os.kill(child.pid, signal.SIGINT) - time.sleep(3) - # The following line causes orphaned ansible processes - # child.terminate(canceled) - canceled = True + try: + os.kill(child.pid, signal.SIGINT) + time.sleep(3) + canceled = True + except OSError: + logger.warn("Attempted to cancel already finished job, ignoring") if idle_timeout and (time.time() - last_stdout_update) > idle_timeout: child.close(True) canceled = True