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
This commit is contained in:
Simon Westphahl 2021-07-05 13:46:07 +02:00
parent 10966948d7
commit 2209ae6d20
1 changed files with 5 additions and 0 deletions

View File

@ -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)