From 844e1a95eebbea2bd4359b3e1395d202da0f0d39 Mon Sep 17 00:00:00 2001 From: Joseph Lynch Date: Thu, 3 Sep 2015 10:51:32 -0700 Subject: [PATCH 1/2] Do not unregister the callback in the zk watcher Addresses incompatibility of per_callback threading in ZK, the way that synapse calls unsubscribe within the callback, and ruby 2.X really not liking joining on the current running thread. Should fix #137 #99 and possibly #94 --- lib/synapse/service_watcher/zookeeper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/synapse/service_watcher/zookeeper.rb b/lib/synapse/service_watcher/zookeeper.rb index 2f7b8025..00896181 100644 --- a/lib/synapse/service_watcher/zookeeper.rb +++ b/lib/synapse/service_watcher/zookeeper.rb @@ -84,8 +84,7 @@ def watch return if @zk.nil? log.debug "synapse: setting watch at #{@discovery['path']}" - @watcher.unsubscribe unless @watcher.nil? - @watcher = @zk.register(@discovery['path'], &watcher_callback) + @watcher = @zk.register(@discovery['path'], &watcher_callback) unless @watcher # Verify that we actually set up the watcher. unless @zk.exists?(@discovery['path'], :watch => true) From dd983639b63aa8891feb8ccadb2bf49c3ee86074 Mon Sep 17 00:00:00 2001 From: Joseph Lynch Date: Thu, 3 Sep 2015 21:49:00 -0700 Subject: [PATCH 2/2] Handle path going away properly --- lib/synapse/service_watcher/zookeeper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/synapse/service_watcher/zookeeper.rb b/lib/synapse/service_watcher/zookeeper.rb index 00896181..3f3c013c 100644 --- a/lib/synapse/service_watcher/zookeeper.rb +++ b/lib/synapse/service_watcher/zookeeper.rb @@ -89,7 +89,7 @@ def watch # Verify that we actually set up the watcher. unless @zk.exists?(@discovery['path'], :watch => true) log.error "synapse: zookeeper watcher path #{@discovery['path']} does not exist!" - raise RuntimeError.new('could not set a ZK watch on a node that should exist') + zk_cleanup end log.debug "synapse: set watch at #{@discovery['path']}" end