Node js + Mysql : cannot enqueue because of fatal errors
<p>I'm running a application with node js (more specifically express js) and I save some datas with a mysql client. </p>

<p>It perfectly works for some time with no issue but then all of suddden I get these erros:</p>

<blockquote>
  <p>Trace: Cannot enqueue Quit after fatal error.
      at Protocol._validateEnqueue (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:218:11)
      at Protocol._enqueue (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:135:13)
      at Protocol.quit (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:88:23)
      at PoolConnection.end (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\Connection.js:255:18)
      at Pool._purgeConnection (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\Pool.js:259:16)
      at PoolConnection._removeFromPool (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\PoolConnection.js:70:8)
      at PoolConnection. (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\PoolConnection.js:29:12)
      at emitOne (events.js:77:13)
      at PoolConnection.emit (events.js:169:7)
      at PoolConnection.Connection._handleProtocolError (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\Connection.js:439:8)
  Trace: Cannot enqueue Query after fatal error.
      at Protocol._validateEnqueue (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:218:11)
      at Protocol._enqueue (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:135:13)
      at PoolConnection.query (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\Connection.js:214:25)
      at Object.fetchDatas (C:\nodejs\twelve-coiffure\public\javascripts\twelvebase.js:94:12)
      at C:\nodejs\twelve-coiffure\routes\index.js:7:7
      at Layer.handle [as handle_request] (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\layer.js:95:5)
      at next (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\route.js:131:13)
      at Route.dispatch (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\layer.js:95:5)
      at C:\nodejs\twelve-coiffure\node_modules\express\lib\router\index.js:277:22
  C:\nodejs\twelve-coiffure\public\javascripts\twelvebase.js:26
          throw(message);
          ^</p>
  
  <p>Error: Cannot enqueue Query after fatal error.
      at Protocol._validateEnqueue (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:199:16)
      at Protocol._enqueue (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\protocol\Protocol.js:135:13)
      at PoolConnection.query (C:\nodejs\twelve-coiffure\node_modules\mysql\lib\Connection.js:214:25)
      at Object.fetchDatas (C:\nodejs\twelve-coiffure\public\javascripts\twelvebase.js:94:12)
      at C:\nodejs\twelve-coiffure\routes\index.js:7:7
      at Layer.handle [as handle_request] (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\layer.js:95:5)
      at next (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\route.js:131:13)
      at Route.dispatch (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (C:\nodejs\twelve-coiffure\node_modules\express\lib\router\layer.js:95:5)
      at C:\nodejs\twelve-coiffure\node_modules\express\lib\router\index.js:277:22</p>
</blockquote>

<p>The problem is that I really can't find where the issue comes from in my code, and I don't even know why sometimes in works and sometimes not.</p>

<p>Here is my code to start the database:</p>

<pre><code>var mysql = require('mysql');
var dbPool = mysql.createPool({
 connectionLimit: 50,
 waitForConnections: true,
 queueLimit: 0,
 host: '*my host*',
 user: '*me*',
 password: '*my password*',
 database: '*heroku database*',
 wait_timeout:28800,
 connect_timeout:10,
 debug:true
});

dbPool.getConnection(function(err, connection) {
 if (err) throw (err);

 var db = connection;

 fetchDatas = function(callback) {

    // openDatabase();

    var servicesFemmes, servicesHommes, products;

    db.query("SELECT * FROM servicesFemmes", function(err, servicesFemmes, fields) {

        if (err) {
            callback(sendError(err));
        } else {

            db.query("SELECT * FROM servicesHommes", function(err, servicesHommes, fields) {
                if (err) {
                    callback(sendError(err));
                } else {
                    db.query("SELECT * FROM produits", function(err, products, fields) {
                        if (err) {
                            callback(sendError(err));
                        } else {
                            db.query("SELECT * FROM carousel", function(err, carousel, fields) {
                                if (err) {
                                    callback(sendError(err));
                                } else {
                                    callback(null, servicesFemmes, servicesHommes, products, carousel);
                                }
                            });
                        }
                    });
                }
            });
        }
    });
}
}
}
</code></pre>

<p>Of course I'm calling fetchDatas() from another file to get all the datas to display.</p>