From 21cf769ae78021cf6968666ab7dc5e779835fd01 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Fri, 27 Sep 2024 00:41:25 +0530 Subject: [PATCH 1/2] mgr/mgr_util: don't set event when it is already set In class RTimer in mgr_util.py, "self.finished.set()" is run even though the event self.finished was set just now. If it wasn't set, the while loop the precedes it would've never finished running. Therefore, remove this redundant line of code. Signed-off-by: Rishabh Dave --- src/pybind/mgr/mgr_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index 67246545eea..a999b6525e9 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -88,7 +88,6 @@ class RTimer(Timer): while not self.finished.is_set(): self.finished.wait(self.interval) self.function(*self.args, **self.kwargs) - self.finished.set() except Exception as e: logger.error("task exception: %s", e) raise From b96d714b23b3f5294df9c28d1f6f5488c4253853 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Fri, 27 Sep 2024 00:43:31 +0530 Subject: [PATCH 2/2] mgr/mgr_util: log traceback when exception occurs in RTimer.run() When an exception occurs in class RTimer of mgr_util.py, only the exception message is logged but not only this is insufficient for debugging but also it is hard to spot in logs. This should not be the case, especially for an occurring exception. Therefore, add code to log traceback and exception name as well along with exception's message. Log entry before this patch - 2024-09-27T00:22:38.656+0530 7f05c7e006c0 0 [volumes ERROR mgr_util] task exception: dummy exception for testing Log entry with this patch - 2024-09-27T00:40:26.509+0530 7f61d64006c0 0 [volumes ERROR mgr_util] exception encountered in RTimer instance "": Traceback (most recent call last): File "/home/rishabh/repos/ceph/minor3/src/pybind/mgr/mgr_util.py", line 91, in run self.function(*self.args, **self.kwargs) File "/home/rishabh/repos/ceph/minor3/src/pybind/mgr/volumes/fs/stats_util.py", line 232, in _update_progress_bars raise RuntimeError('dummy exception for testing') RuntimeError: dummy exception for testing Signed-off-by: Rishabh Dave --- src/pybind/mgr/mgr_util.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index a999b6525e9..5d37d478de7 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -22,6 +22,7 @@ import sys from ipaddress import ip_address from threading import Lock, Condition from typing import no_type_check, NewType +from traceback import format_exc as tb_format_exc import urllib from functools import wraps if sys.version_info >= (3, 3): @@ -88,8 +89,9 @@ class RTimer(Timer): while not self.finished.is_set(): self.finished.wait(self.interval) self.function(*self.args, **self.kwargs) - except Exception as e: - logger.error("task exception: %s", e) + except Exception: + logger.error(f'exception encountered in RTimer instance "{self}":' + f'\n{tb_format_exc()}') raise