From 2c2376b8445f95669c2216ac76ca7ea071d9050b Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Mon, 3 Sep 2018 12:22:06 +0200 Subject: [PATCH] Fix node state checks after aquiring lock Node states are never refreshed from Zookeeper before checking if the state changed between looping and aquiring the lock. Change-Id: I259c74cfd5ceb590b124b692e645656a0b85be25 --- nodepool/launcher.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/nodepool/launcher.py b/nodepool/launcher.py index 9c4c2c085..de4267285 100755 --- a/nodepool/launcher.py +++ b/nodepool/launcher.py @@ -553,8 +553,10 @@ class CleanupWorker(BaseCleanupWorker): continue # Double check the state now that we have a lock since it - # may have changed on us. - if node.state != zk.READY: + # may have changed on us. We keep using the original node + # since it's holding the lock. + _node = zk_conn.getNode(node.id) + if _node.state != zk.READY: zk_conn.unlockNode(node) continue @@ -605,8 +607,10 @@ class CleanupWorker(BaseCleanupWorker): continue # Double check the state now that we have a lock since it - # may have changed on us. - if node.state != zk.HOLD: + # may have changed on us. We keep using the original node + # since it's holding the lock. + _node = zk_conn.getNode(node.id) + if _node.state != zk.HOLD: zk_conn.unlockNode(node) continue @@ -716,8 +720,10 @@ class DeletedNodeWorker(BaseCleanupWorker): continue # Double check the state now that we have a lock since it - # may have changed on us. - if node.state not in cleanup_states: + # may have changed on us. We keep using the original node + # since it's holding the lock. + _node = zk_conn.getNode(node.id) + if _node.state not in cleanup_states: zk_conn.unlockNode(node) continue