title: Socket IO not properly closing connection
body: <p>I'm <code>tail</code>ing a log file and stream the new lines to a websocket.</p>
  
  <p>Since I have multiple logs, I let the user choose the log file and then get the details of that log.</p>
  
  <p>The problem is that when I close a connection in order to see a different log, the connection does something weird, that when I start it again, it streams the data twice. If I close the connection and re-open it again, it streams 3 times the data, so on and so forth.</p>
  
  <p>My <code>package.json</code>:</p>
  
  <pre><code>{
      "socket.io": "^2.0.3",
      "socket.io-client": "^2.0.3"
  }
  </code></pre>
  
  <p><strong>Client side</strong></p>
  
  <pre><code>$("#detailsBtn").click(function (e) {
      e.preventDefault();
      $.get('/get/details', {
          // some-data
      }, () =&gt; {
          if (socket) socket.close();
          socket = io('http://localhost:4000', {forceNew: true});
          socket.on('connect', () =&gt; {
              console.log('connected');
          });
          socket.on('newLine', function (msg) {
              // do-stuff
          });
      });
  });
  $('#closeBtn').click(function () {
      socket.disconnect();
      socket.close();
  });
  </code></pre>
  
  <p><strong>Server side</strong></p>
  
  <pre><code>app.get('/details', (req, res) =&gt; {
      const tail = spawn('ssh', ['root@' + req.query.srv, req.query.script]);
      io.on('connection', function (socket) {
          console.log(`connect ${socket.id}`);
          socket.on('disconnect', () =&gt; {
              console.log(`DISconnected ${socket.id}`);
          });
          tail.stdout.on('data', function (data) {
              socket.emit('newLine', {message: data});
          });
      });
      return res.sendStatus(200);
  });
  </code></pre>
  
  <p>Now when simulating the button click, I expect the socket and connection to be closed, in order to make a new one.</p>
  
  <p><strong>Server console log</strong> (each time I click the button only once)</p>
  
  <pre><code>Server listening on localhost:4000
  
  **click on detailsBtn**
  GET /get/details?srv=myserver.google.com&amp;script=%2Fusr%2Fbin%2Ftail 304 16.003 ms - -
  connect YyYHFI9CARpBHaxoAAAB
  **click on closeBtn**
  DISconnected YyYHFI9CARpBHaxoAAAB
  
  **click on detailsBtn**
  GET /get/details?srv=myserver.google.com&amp;script=%2Fusr%2Fbin%2Ftail 304 6.308 ms - -
  connect vzfBnUPHUqYXd5qaAAAC
  connect vzfBnUPHUqYXd5qaAAAC
  **click on closeBtn**
  DISconnected vzfBnUPHUqYXd5qaAAAC
  DISconnected vzfBnUPHUqYXd5qaAAAC
  
  **click on detailsBtn**
  GET /get/details?srv=myserver.google.com&amp;script=%2Fusr%2Fbin%2Ftail 304 4.677 ms - -
  connect 3quEe5G1gFDJ2BvrAAAD
  connect 3quEe5G1gFDJ2BvrAAAD
  connect 3quEe5G1gFDJ2BvrAAAD
  **click on closeBtn**
  DISconnected 3quEe5G1gFDJ2BvrAAAD
  DISconnected 3quEe5G1gFDJ2BvrAAAD
  DISconnected 3quEe5G1gFDJ2BvrAAAD
  </code></pre>
  
  <p>What am I doing wrong?</p>