5

I have a project with Node.js and MySQL. This project run well on local MAC osx. But have an error occurred when deploying on the centOS server. The project have 2 part, 1 is auto run with cron, that auto get data from one web, and update this data into MySQL. This part works fine on both local and online server. But another part is not, that part is display UI on browser, but when accessing it, an error is displayed.

Error: Cannot enqueue Query after fatal error.
    at Protocol._validateEnqueue (/home/xx/node_modules/mysql/lib/p rotocol/Protocol.js:193:16)
    at Protocol._enqueue (/home/xx/node_modules/mysql/lib/protocol/ Protocol.js:129:13)
    at Connection.query (/home/xx/node_modules/mysql/lib/Connection .js:185:25)
    at SessionStore.get (/home/xx/node_modules/express-mysql-sessio n/lib/index.js:92:18)
    at session (/home/xx/node_modules/express-session/index.js:348: 11)
    at Layer.handle [as handle_request] (/home/xx/node_modules/expr ess/lib/router/layer.js:82:5)
    at trim_prefix (/home/xx/node_modules/express/lib/router/index. js:270:13)
    at /home/xx/node_modules/express/lib/router/index.js:237:9
    at Function.proto.process_params (/home/xx/node_modules/express /lib/router/index.js:312:12)
    at /home/xx/node_modules/express/lib/router/index.js:228:12

(this error displayed on both console log and the browser, the project still running after that, so i guess this came from MySQL).

This is the sql connect file: simple is

var config = require('./config');
var mysql = require('mysql'),
    host = config.hostName,
    user = config.databaseUser,
    password = config.databasePassword,
    database = config.databaseName;

module.exports =  mysql.createPool({
  connectionLimit : 10,
  host: host,
  user: user,
  password: password,
  database: database
});

and this is how i call it:

imgExport.selectLast = function(callback){
  conn.getConnection(function(err,conn) {
    querySelectLast15Secon = "SELECT * FROM image WHERE year(moderate_time) = year(curdate()) AND month(moderate_time) = month(curdate()) AND (time(moderate_time) >= (curtime() - 15));";
    conn.query(querySelectLast15Secon, function (err, rows, fields) {
      if (err) throw err;
      callback(rows);
      conn.release();
    })
  });
};

i used console.dir(conn.threadId) before a code to debug, and it printed like that, so what is that mean? (each number in lines)

6177 6180 6181 6184 6183 6185 6176 6178 6179 6177 6183 6184 6185 6182 6180 6177 6176 6181 6183

tadman
  • 208,517
  • 23
  • 234
  • 262
The Mechanic
  • 145
  • 1
  • 1
  • 12
  • Are the versions of MySQL the same on both systems? – Brandon Buck Oct 31 '14 at 02:54
  • Have you done a fresh `npm install` on each system, or at least an `npm rebuild`? There are native components to many database connectors. – Brad Oct 31 '14 at 03:06
  • @BrandonBuck : MacOSX :mysql Ver 14.14 Distrib 5.6.19, for osx10.9 (x86_64) using EditLine wrapper on CentOS : mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5. Brad: yes i already did it 1 – The Mechanic Oct 31 '14 at 03:07
  • @Brad FWIW the `mysql` module is pure javascript, no compiling involved. – mscdex Oct 31 '14 at 03:18
  • @mscdex He didn't tell us what module he's using. But I suppose it probably is Felix's, in which case you're right. (That's actually why I use Felix's module myself, for applications that don't do a ton of querying. It makes it convenient to drop the whole directory, `node_modules` and all, somewhere else.) – Brad Oct 31 '14 at 03:24

1 Answers1

1

Fixed! The problem is from express-sql-session! I removed it from the code and its works fine. So i think i need to report this problems for them in here:

https://github.com/chill117/express-mysql-session/issues

I think there is some issue with connection.end() in that module. Dont know where but maybe should take a time to find it out.

The Mechanic
  • 145
  • 1
  • 1
  • 12
  • Hello @The Mechanic, can you please provide a detailed solution of what you did to fix this? – Dom Nov 11 '21 at 00:47