title: Errors going to 2 dynos on Heroku with socket.io / socket.io-redis / rediscloud / node.js
body: <p>I have a node.js / socket.io app running on Heroku.  I am using socket.io-redis with RedisCloud to allow users who connect to different dynos to communicate, as described <a href="http://socket.io/docs/using-multiple-nodes/" rel="nofollow" title="here">here</a>.  </p>
  
  <p>From my app.js:</p>
  
  <pre><code>var express = require('express'),
  app = express(),
  http = require('http'),
  server = http.createServer(app),
  io = require('socket.io').listen(server),
  redis = require('redis'),
  ioredis = require('socket.io-redis'),
  url = require('url'),
  redisURL = url.parse(process.env.REDISCLOUD_URL),
  </code></pre>
  
  <p>And later in app.js ...</p>
  
  <pre><code>var sub1 = redis.createClient(redisURL.port, redisURL.hostname, {
      no_ready_check: true,
      return_buffers: true
  });
  sub1.auth(redisURL.auth.split(":")[1]);
  var pub1 = redis.createClient(redisURL.port, redisURL.hostname, {
      no_ready_check: true,
      return_buffers: true
  });
  pub1.auth(redisURL.auth.split(":")[1]);
  var redisOptions = {
      pubClient: pub1,
      subClient: sub1,
      host: redisURL.hostname,
      port: redisURL.port
  };
  if (io.adapter) {
      io.adapter(ioredis(redisOptions));
      console.log("mylog: io.adapter found");
  }
  </code></pre>
  
  <p>It is kind of working -- communication is succeeding between dynos.  </p>
  
  <p>Three issues that happen with 2 dynos but not with 1 dyno: </p>
  
  <p>1) There is a login prompt which comes up and works reliably with 1 dyno but is hit-and-miss with 2 dynos -- may not come up and may not work if it does come up.   It is (or should be) triggered by the io.sockets.on('connection') event.</p>
  
  <p>2) I'm seeing a lot of disconnects in the server log. </p>
  
  <p>3) Also lots of errors in the client console on Chrome, for example:</p>
  
  <pre><code>socket.io.js:5039 WebSocket connection to 'ws://example.mydomain.com/socket.io/?EIO=3&amp;transport=websocket&amp;sid=F8babuJrLI6AYdXZAAAI' failed: Error during WebSocket handshake: Unexpected response code: 503
  
  socket.io.js:2739 POST http://example.mydomain.com/socket.io/?EIO=3&amp;transport=polling&amp;t=1419624845433-63&amp;sid=dkFE9mUbvKfl_fiPAAAJ net::ERR_INCOMPLETE_CHUNKED_ENCODING
  
  socket.io.js:2739 GET http://example.mydomain.com/socket.io/?EIO=3&amp;transport=polling&amp;t=1419624842679-54&amp;sid=Og2ZhJtreOG0wnt8AAAQ 400 (Bad Request)
  
  socket.io.js:3318 WebSocket connection to 'ws://example.mydomain.com/socket.io/?EIO=3&amp;transport=websocket&amp;sid=ITYEPePvxQgs0tcDAAAM' failed: WebSocket is closed before the connection is established.
  </code></pre>
  
  <p>Any thoughts or suggestions would be welcome.</p>