title: MySQL giving "read ECONNRESET" error after idle time on node.js server
body: <p>I'm running a Node server connecting to MySQL via the node-mysql module. Connecting to and querying MySQL works great initially without any errors, however, the first query after leaving the Node server idle for a couple hours results in an error. The error is the familiar <code>read ECONNRESET</code>, coming from the depths of the node-mysql module.</p>
  
  <p>A stack trace (note that the three entries of the trace belong to my app's error reporting code):</p>
  
  <pre><code>Error
  at exports.Error.utils.createClass.init (D:\home\site\wwwroot\errors.js:180:16)
  at new newclass (D:\home\site\wwwroot\utils.js:68:14)
  at Query._callback (D:\home\site\wwwroot\db.js:281:21)
  at Query.Sequence.end (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\sequences\Sequence.js:78:24)
  at Protocol.handleNetworkError (D:\home\site\wwwroot\node_modules\mysql\lib\protocol\Protocol.js:271:14)
  at PoolConnection.Connection._handleNetworkError (D:\home\site\wwwroot\node_modules\mysql\lib\Connection.js:269:18)
  at Socket.EventEmitter.emit (events.js:95:17)
  at net.js:441:14
  at process._tickCallback (node.js:415:13)
  </code></pre>
  
  <p>This error happens both on my cloud Node server and MySQL server as well as a local setup of both.</p>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>Does this problem appear to be a disconnection of Node's connection to my MySQL server(s), perhaps due to a connection lifetime limitation?</p></li>
  <li><p>When using connection pools, node-mysql is supposed to gracefully handle disconnections and prune them from the pool. Is it not aware of the disconnect until I make a query, thus making the error unavoidable?</p></li>
  <li><p>Considering that I see the "read ECONNRESET" error a lot in other StackOverflow posts, should I be looking elsewhere from MySQL to diagnose the problem?</p></li>
  </ol>
  
  <p><strong>Update:</strong> After more browsing, I think my issue is a duplicate of <a href="https://stackoverflow.com/questions/22602362/nodejs-server-with-mysql-hangs">this one</a>. It appears his connection is disconnecting as well, but no one has suggested how to keep the connection alive or how to address the error outside of failing on the first query back.</p>