title: Socket.IO Double Connection
body: <p>I have a simple node.js server set up with an angular.js frontent and I am trying to implement Socket.IO so I can live update data on my page but I am running into an issue with double Socket.IO connections opening and hanging my page.</p>
  
  <pre><code>var self = this;
  
  self.app = express();
  self.http = http.Server(self.app);
  
  self.config = config;
  
  self.io = require('socket.io')(self.http);
  
  self.io.on('connect', function() {
      console.log('Connected');
  });
  </code></pre>
  
  <p>and in my angular.js factory I have </p>
  
  <pre><code>var socket = io.connect();
  </code></pre>
  
  <p>If I load up my page on Safari or Chrome on iOS (pretty sure it's happening on Android too but I don't have one to test with, I cannot replicate when I'm not on a mobile device) and refresh the page it will connect correctly and then at random on a page refresh or even sometimes on a new page load I will see in the log that it connected twice at the same time which causes the page to hang on the socket.io request</p>
  
  <p><a href="https://i.stack.imgur.com/pMxcq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pMxcq.png" alt=""></a></p>
  
  <p>and because it hangs on that request the other requests I do will be stuck waiting for that one to complete and the page will never load.</p>