From: Sebastian Wagner Date: Mon, 23 Apr 2018 08:13:28 +0000 (+0200) Subject: mgr/dashboard: Fix data race and use-before-assignment X-Git-Tag: v13.1.0~139^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3a795a42d504e2452ffe86870b813b1882e6fd84;p=ceph.git mgr/dashboard: Fix data race and use-before-assignment The race happes, if a task raises an exception very early. Then, `self.getter_thread.event` fails as `getter_thread` is already `None` Also fix use-before-assignment, as `t0` and `t1` are only defined, if no exception was raised. Signed-off-by: Sebastian Wagner --- diff --git a/src/pybind/mgr/dashboard/tools.py b/src/pybind/mgr/dashboard/tools.py index 6175140bd719..05b42d8469ac 100644 --- a/src/pybind/mgr/dashboard/tools.py +++ b/src/pybind/mgr/dashboard/tools.py @@ -113,18 +113,21 @@ class ViewCache(object): # pylint: disable=broad-except def run(self): + t0 = 0 + t1 = 0 try: t0 = time.time() logger.debug("VC: starting execution of %s", self.fn) val = self.fn(*self.args, **self.kwargs) t1 = time.time() except Exception as ex: - logger.exception("Error while calling fn=%s ex=%s", self.fn, - str(ex)) - self._view.value = None - self._view.value_when = None - self._view.getter_thread = None - self._view.exception = ex + with self._view.lock: + logger.exception("Error while calling fn=%s ex=%s", self.fn, + str(ex)) + self._view.value = None + self._view.value_when = None + self._view.getter_thread = None + self._view.exception = ex else: with self._view.lock: self._view.latency = t1 - t0