title: getaddrinfo ENOTFOUND after updating socket.io
body: <p>I have a service where clients subscribe to a socket connection and listens for updates coming down the pipeline. Once a client has subscribed to a room we send a sendSyncRequest (view below) which calls another service to grab any updated data and it publishes it back down the client through the socket room.</p>
  
  <p>The issue that keeps popping comes when the socket.io version was updated from v1.7.3 to v2.1.1. After deploying the service to a production server everything goes a bit haywire and we start seeing a <code>getaddrinfo ENOTFOUND</code> error that pops up everytime sendSyncRequest gets hit.</p>
  
  <p>Some additional information:</p>
  
  <ul>
  <li>OS Version: Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-74-generic x86_64)</li>
  <li>Node Version: 4.4.0</li>
  <li>Socket.io Version: 2.2.1</li>
  <li>Request Version: 2.81.0</li>
  </ul>
  
  <p>Error screenshot: 
  <a href="https://i.stack.imgur.com/gN7hI.png" rel="nofollow noreferrer">getadrrinfo ENOTFOUND error</a></p>
  
  <p>sendSyncRequest Code:</p>
  
  <pre><code>function sendSyncRequest(service, accessToken, lastUpdate, socketId, method) {
    var uri = service.scheme + '://' + service.host + ':' + service.port + service.path;
  
    var options = {
      uri:       uri,
      strictSSL: false,
      timeout:   NO_RESPONSE_TIMEOUT,
      json:      true,
      headers: {
        Authorization: 'Bearer ' + accessToken
      }
   };
  
   if (method === 'get') {
     options.qs = {
       lastUpdate: lastUpdate,
       socketId: socketId
     };
   } else {
     options.body = {
     lastUpdate: lastUpdate,
     socketId: socketId
   };
  }
  
    request[method || 'post'](options, function(err, response) {
      if (err) {
        log.error('sendSyncRequest', err);
        return;
      }
  
      if (response.statusCode !== 200) {
        log.error('sendSyncRequest %d %s', response.statusCode, http.STATUS_CODES[response.statusCode]);
        return;
      }
    }
  );}
  </code></pre>
  
  <p>Socket Server Code:</p>
  
  <pre><code>module.exports.init = function (callback) {
  log.info('starting new Socket.IO server');
  io.origins('*:*');
  
  log.info('initializing socket.io server');
  
  io.attach(server.getServer());
  
  io.on('disconnect', function (socket) {
      log.info('socket.io server disconnect ', socket);
  });
  
  io.on('connection', function (socket) {
      log.info('new socket.io client %s@%s (%s) connection',
          socket);
  
      socket.emit('successful_connection', {socketId: socket.id});
  
      socket.on('disconnecting', function () {
          log.info('socket.io client %s@%s (%s) disconnecting',
              socket.userData.user,
              socket.userData.domain,
              socket.id);
  
          for (var room in socket.rooms) {
              if (socket.rooms.hasOwnProperty(room)) {
                  var count = io.sockets.adapter.rooms[room].length;
                  log.debug('current room %s connected client count = %d', room, count);
  
                  if (count &lt;= 1) {
                      log.info('unsubscribing from room %s', room);
                      cacheClient.unsubscribe(room);
                  }
              }
          }
      });
  });
  };
  </code></pre>
  
  <p>We have also looked into the following github issues which talks about the file descriptor limits, but ultimately this feels like a short term solution.</p>
  
  <p><a href="https://github.com/nodejs/node-v0.x-archive/issues/5545#issuecomment-19007785" rel="nofollow noreferrer">https://github.com/nodejs/node-v0.x-archive/issues/5545#issuecomment-19007785</a></p>
  
  <p><a href="https://github.com/nodejs/node-v0.x-archive/issues/5488" rel="nofollow noreferrer">https://github.com/nodejs/node-v0.x-archive/issues/5488</a></p>
  
  <p>If anyone has any suggestions or fixes, please share, we welcome all the help we can get.</p>