From 2209ae6d205393400553247a6f9b0867f3140e89 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Mon, 5 Jul 2021 13:46:07 +0200 Subject: [PATCH] Don't process build state watches w/o data This fixes a race condition that mainly seems to show up in the test of the executor API. The race happens when a "slow" change watch tried to retrieve data of a znode that was deleted in the meantime. Traceback (most recent call last): File "/home/zuul/src/opendev.org/zuul/zuul/zuul/zk/watchers.py", line 177, in _log_func_exception result = self._func(data, stat, event) File "/home/zuul/src/opendev.org/zuul/zuul/zuul/zk/executor.py", line 107, in watch return self._watchBuildState(path, data, stat, event) File "/home/zuul/src/opendev.org/zuul/zuul/zuul/zk/executor.py", line 114, in _watchBuildState content = self._bytesToDict(data) File "/home/zuul/src/opendev.org/zuul/zuul/zuul/zk/executor.py", line 426, in _bytesToDict return json.loads(data.decode("utf-8")) AttributeError: 'NoneType' object has no attribute 'decode' Change-Id: I642ad04f7909ae7917e2798d2789fa309cb76692 --- zuul/zk/executor.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/zuul/zk/executor.py b/zuul/zk/executor.py index 2effe7063e..63161a1bd2 100644 --- a/zuul/zk/executor.py +++ b/zuul/zk/executor.py @@ -109,6 +109,11 @@ class ExecutorApi(ZooKeeperSimpleBase): def _watchBuildState(self, path, data, stat, event=None): if not event or event.type == EventType.CHANGED: + # Don't process change events w/o any data. This can happen when + # a "slow" change watch tried to retrieve the data of a znode that + # was deleted in the meantime. + if data is None: + return # As we already get the data and the stat value, we can directly # use it without asking ZooKeeper for the data again. content = self._bytesToDict(data)