title: Node.js - server closed the connection?
body: <p>I'm running a web app on a Node.js server and I need it to be online all the time, so I'm using forever. But here is what I'm getting after a period of time:</p>
  
  <pre><code>Error: Connection lost: The server closed the connection.
      at Protocol.end (/home/me/private/app/node_modules/mysql/lib/protocol/Protocol.js:73:13)
      at Socket.onend (stream.js:79:10)
      at Socket.EventEmitter.emit (events.js:117:20)
      at _stream_readable.js:910:16
      at process._tickCallback (node.js:415:13)
  error: Forever detected script exited with code: 8
  error: Forever restarting script for 3 time
  </code></pre>
  
  <p>I have two more servers that have been running for about 10 days straight. I have a "keepalive" loop on all servers, making a "select 1" mysql query every 5 minutes or so, but it seems like it doesn't make any difference.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>My other servers were giving a similar error, I think it was "connection timeout", so I put this function:</p>
  
  <pre><code>function keepalive() {
      db.query('select 1', [], function(err, result) {
          if(err) return console.log(err);    
          console.log('Successful keepalive.');
      });
  }
  </code></pre>
  
  <p>And it fixed my other two servers. But on my main server I'm still getting the error above.</p>
  
  <p>Here is how I'm starting my main server:</p>
  
  <pre><code>var https = require('https');
  https.createServer(options, onRequest).listen(8000, 'mydomain.com');
  </code></pre>
  
  <p>I'm not sure what code are you interested in seeing. Basically the server is a REST API and it needs to stay up all the time. It's getting about 2-5, maybe 10 requests per minute.</p>