title: Tensorflow server always bound to localhost
body: <p>clusterspec.json</p>
  
  <pre><code>{ "worker":
   [ "192.168.190.5:2222"
   , "192.168.190.6:2222"
   , "192.168.190.8:2222"
   ]
  ,"master":
   [ "192.168.190.9:2222" ]
  }
  </code></pre>
  
  <p>worker.py</p>
  
  <pre><code>import json
  import tensorflow as tf
  
  with open('clusterspec.json', 'r') as f:
     clusterspec = json.load(f)
  
  cluster = tf.train.ClusterSpec(clusterspec)
  server = tf.train.Server(cluster, job_name="worker", task_index=0)
  #task_index is set to 0,1,or 2 for the different workers
  </code></pre>
  
  <p>master.py</p>
  
  <pre><code>import json
  import tensorflow as tf
  
  with open('clusterspec.json', 'r') as f:
      clusterspec = json.load(f)
  
  cluster = tf.train.ClusterSpec(clusterspec)
  
  a = tf.constant(3)
  b = tf.constant(2)
  
  with tf.device("/job:worker/task:0"):
      x = tf.mul(a, b)
  
  with tf.device("/job:worker/task:1"):
      y = tf.mul(a, b)
  
  server = tf.train.Server(cluster, job_name="master", task_index=0)
  with tf.Session(server.target) as sess:
      print "here"
      print(sess.run([x, y]))
  </code></pre>
  
  <p>The master hangs at 
      sess.run([x,y])</p>
  
  <p>I have noticed that when I execute worker.py on all the workers, I always get this message:</p>
  
  <pre><code>I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:206]   Initialize HostPortsGrpcChannelCache for job master -&gt; {192.168.190.9:2222}
  I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:206] Initialize HostPortsGrpcChannelCache for job worker -&gt; {localhost:2222,  192.168.190.6:2222, 192.168.190.8:2222}
  I tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc:203] Started server with target: grpc://localhost:2222
  </code></pre>
  
  <p>So, it is always binding to the local interface, and not 192.168.190.x. Is this the correct behavior? Could someone please explain why the master hangs?</p>
  
  <p>----SIMPLIFIED CODE BASED ON THE COMMENTS---</p>
  
  <p>clusterspec.json</p>
  
  <pre><code>{ "worker":
   [ "192.168.190.5:2222"]
  }
  </code></pre>
  
  <p>worker.py</p>
  
  <pre><code>same as above
  </code></pre>
  
  <p>master.py</p>
  
  <pre><code>import json
  import tensorflow as tf
  
  with open('clusterspec.json', 'r') as f:
      clusterspec = json.load(f)
  
  cluster = tf.train.ClusterSpec(clusterspec)
  
  a = tf.constant(3)
  b = tf.constant(2)
  
  with tf.device("/job:worker/task:0"):
      x = tf.mul(a, b)
  
  with tf.Session('grpc://192.168.190.5:2222') as sess:
      print "here"
      print(sess.run([x]))
  </code></pre>
  
  <p>As before, master.py hangs on </p>
  
  <pre><code>sess.run([x])
  </code></pre>
  
  <p>One observation: </p>
  
  <pre><code>dev@enterprise-3:~$ ps ax | grep master.py
  7986 pts/1    Sl+    0:01 python master.py
  8008 pts/0    S+     0:00 grep --color=auto master.py
  
  dev@enterprise-1:~$ ps ax | grep worker.py
  7952 pts/0    S+     0:00 grep --color=auto worker.py
  </code></pre>
  
  <p><code>worker.py</code> doesn't seem to persist..</p>