From 510345e5adea2bc3a4e4a7c0df65ed6d7c24d0a8 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 4 Nov 2015 18:10:55 -0500 Subject: Log an error on an uncaught exception in a thread Exceptions in synchronous tasks get caught by the olso_messaging code but for asynchronous tasks run in threads with nothing wait()ing for them, there is no top level error handling, and hence no logging. (Tracebacks would be written to stderr, so systemd users would see them only in the journal rather than heat-engine.log, and other users would quite likely lose them altogether.) This change ensures that any uncaught exceptions are logged as errors. Change-Id: I9410aa7ffd83391ea4db13c6e8cf49f26d3049fb Closes-Bug: #1492427 (cherry picked from commit 03d9aebbc7d5fba048fa9f39813704e70dee9c5d) --- heat/engine/service.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/heat/engine/service.py b/heat/engine/service.py index 2f1d20021..069d6d3ef 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -116,9 +116,20 @@ class ThreadGroupManager(object): """ if stack_id not in self.groups: self.groups[stack_id] = threadgroup.ThreadGroup() - return self.groups[stack_id].add_thread(self._start_with_trace, - self._serialize_profile_info(), - func, *args, **kwargs) + + def log_exceptions(gt): + try: + gt.wait() + except Exception: + LOG.exception(_LE('Unhandled error in asynchronous task')) + except BaseException: + pass + + th = self.groups[stack_id].add_thread(self._start_with_trace, + self._serialize_profile_info(), + func, *args, **kwargs) + th.link(log_exceptions) + return th def start_with_lock(self, cnxt, stack, engine_id, func, *args, **kwargs): """ -- cgit v1.2.1