title: Using Socket.io and Redis on Heroku with Node.js
body: <p>I'm trying to deploy an app to Heroku using Node.js and Socket.io with Redis. I have set up Socket.io to use XHR long polling as <a href="https://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku" rel="nofollow">specified by Heroku</a>, and it works perfectly if I only have one dyno, but it doesn't work when I scale it to use multiple dynos. </p>
  
  <p>Initially I was using an MemoryStore in Socket.io, and when I scaled it up using "heroku ps:scale web=2", it started working intermittently, and giving this error in the client:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Property 'open' of object #&lt;Transport&gt; is not a function </p>
  </blockquote>
  
  <p>I found in the <a href="https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO" rel="nofollow">Socket.io documentation</a> that <em>"if you want to scale to multiple process and / or multiple servers you can use our RedisStore which uses the Redis NoSQL database as man in the middle"</em></p>
  
  <p>So, I created a RedisStore:</p>
  
  <pre><code>var newRedisStore = new RedisStore({
    redisPub : pub,
    redisSub : sub,
    redisClient : client
  });
  </code></pre>
  
  <p>and configured Socket.io to use it:</p>
  
  <pre><code>//set up Web Socket Server
  io.configure(function () { 
    io.set("transports", ["xhr-polling"]);
    io.set("polling duration", 10);
    io.set('store', newRedisStore);
  });
  </code></pre>
  
  <p>And it all works perfectly locally and with one web dyno in Heroku. But as soon as I scale it to more than one process, it starts intermittently not working again, although now I don't get the error anymore. So, I'm not sure where to go from here.</p>
  
  <p>These are the logs I'm getting from Heroku with 2 processes:</p>
  
  <blockquote>
    <p>2012-06-16T15:36:12+00:00 app[web.2]: debug: setting poll timeout<br>
    2012-06-16T15:36:12+00:00 app[web.2]: debug: clearing poll timeout<br>
    2012-06-16T15:36:12+00:00 app[web.2]: debug: xhr-polling writing<br>
    7:::1+0 2012-06-16T15:36:12+00:00 app[web.2]: warn: client not<br>
    handshaken client should reconnect 2012-06-16T15:36:12+00:00<br>
    app[web.2]: debug: set close timeout for client 15718037491002932534<br>
    2012-06-16T15:36:12+00:00 app[web.2]: debug: cleared close timeout for<br>
    client 15718037491002932534 2012-06-16T15:36:12+00:00 app[web.2]:<br>
    info: transport end (error) 2012-06-16T15:36:12+00:00 app[web.2]:<br>
    debug: discarding transport<br></p>
  </blockquote>