From 7e7ff8137dfcbe28f14fb513f00e1686df50c41a Mon Sep 17 00:00:00 2001 From: chris meyers Date: Mon, 2 Apr 2018 11:41:30 -0400 Subject: [PATCH] more gracefully account for undefined stdout * It's possible to have an exception raised in BaseTask.run() before the stdout handler gets defined. This is problematic when the exception handler tries to access that undefined var .. causing another exception. Note that the second exception is caught also but it's not desirable to lose the first exception. * This fix checks to see if the stdout handler var is defined before calling it's methods. Thus, we retain the original error message. --- awx/main/tasks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 3aeaadd786..0de7094100 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -993,9 +993,10 @@ class BaseTask(LogErrorsTask): logger.exception('%s Exception occurred while running task', instance.log_format) finally: try: - stdout_handle.flush() - stdout_handle.close() - event_ct = getattr(stdout_handle, '_event_ct', 0) + if stdout_handle: + stdout_handle.flush() + stdout_handle.close() + event_ct = getattr(stdout_handle, '_event_ct', 0) logger.info('%s finished running, producing %s events.', instance.log_format, event_ct) except Exception: