title: ETIMEDOUT problems with node.js & amqp
body: <p>I have 2 producers and two consumers in my project that uses rabbitmq via amqp module in node.js.</p>
  
  <p>The code for establishing connection for consumers looks like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>function init_consumers( ) {
      console.log( 'mq: consumers connection established. Starting to init stuff..' );
      global.queue.consumers.connection = con_c;
  
      var fq_name = global.queue.fq_name;
      var aq_name = global.queue.aq_name;
      var q_opts = { durable:true };
      var subscr_opt = { ack: true, prefetchCount: 1 };
  
      var fq = con_c.queue( fq_name, q_opts, function() {
          console.log( 'mq: consumer f queue prepared. ');
          global.queue.consumers.fq = fq;
          fq.subscribe( subscr_opt, function(msg) {
              global.controllers.fc.ParseF( msg, function() { global.queue.consumers.fq.shift(); } );
          });
      });
  
      var aq = con_c.queue( aq_name, q_opts, function() {
          console.log( 'mq: consumer a queue prepared. ');
          global.queue.consumers.aq = aq;
          aq.subscribe( subscr_opt, function(msg) {
              global.controllers.fc.ParseAndSaveToDB( msg, function() { global.queue.consumers.aq.shift(); } );
          });
      });
  }
  
  
  // connect and init 
  var con_c = amqp.createConnection( { url: global.queue.consumers.host }, global.queue.con_extra_options );
  con_c.on( 'ready', init_consumers );
  con_c.on( 'error', function(e) {
      console.log( 'consumer error', e );
      con_c.end();
      if( typeof global.queue.consumers.connection !== 'undefined' ) { global.queue.consumers.connection.end(); }
  });
  </code></pre>
  
  <p>Connection extra options are:</p>
  
  <pre class="lang-js prettyprint-override"><code>con_extra_options:  {   reconnect:                  true, // Enable reconnection
                          reconnectBackoffStrategy:   'linear',
                          reconnectBackoffTime:       5000, // Try reconnect 5 seconds
                      },
  </code></pre>
  
  <p>After project has launched in rabbitmq management console I clearly see that there is 1 connection established with 2 channels. Very good.</p>
  
  <p>Then, it works just fine until an error (possible related to some disconnections) happens, giving me this output in console:</p>
  
  <pre><code>consumer error { [Error: read ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'read' }
  </code></pre>
  
  <p>The problem is that when this error happens, amqp tries to reconnect to queue server, but it seems that even with my code above the connection remains opened. In result after several hours of work I have 10 connections with like 50 channels opened, and the only thing remains for me is just to restart the project.</p>
  
  <p>So, I have two questions:</p>
  
  <ol>
  <li>Why this kind of error appears?</li>
  <li>What modifications should I implement to stop the growth of connections and channels with time?</li>
  </ol>