title: ZMQ dealer-router-dealer pattern
body: <p>I am currently working on a project that requires some communication over the network and I am using ZMQ. The main goal of the project is to have a central node which services clients which can connect at any time. For each client connected, the central node should spawn a corresponding worker thread and proxy the communication between the two. All communication is happening over tcp.</p>
  
  <p>Clients and workers need to send and receive messages at any time so they are <code>ZMQ_DEALER</code> type sockets and the central node is <code>ZMQ_ROUTER</code>.</p>
  
  <p>I have a problem that after some time all threads in the central node (the router and all workers) will deadlock. Upon examining the stacks of all ZMQ threads they are all blocked on <code>SockWaitForSingleObject</code> on win and <code>poll</code>/<code>epoll_wait</code> on linux.</p>
  
  <p>I have made somewhat minimal example that reproduces the problem <a href="http://pastebin.com/aUTg7RJY" rel="nofollow">http://pastebin.com/aUTg7RJY</a> (It's in pastebin as it's rather long)</p>
  
  <p>In the example the clients are in the same process as the workers and all are pre-connected, but in the real case they aren't but this does not make any difference - in both cases the problem is the same.</p>
  
  <p>I tried to modify the example code to use <code>inproc</code> protocol for the worker-node communication but the problem still persists <a href="http://pastebin.com/MJBHNyiF" rel="nofollow">http://pastebin.com/MJBHNyiF</a></p>
  
  <p>I don't know if my problem is with the architecture of the network or I am misusing the ZMQ lib. I will appreciate any help! </p>