NodeJS running on Mac, and have an error occurred when deploying on centOS
Asked Answered
A

1

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

Adjourn answered 31/10, 2014 at 2:50 Comment(5)
Are the versions of MySQL the same on both systems?Buhrstone
Have you done a fresh npm install on each system, or at least an npm rebuild? There are native components to many database connectors.Sodomite
@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 1Adjourn
@Sodomite FWIW the mysql module is pure javascript, no compiling involved.Mimetic
@Mimetic 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.)Sodomite
A
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.

Adjourn answered 31/10, 2014 at 3:28 Comment(1)
Hello @The Mechanic, can you please provide a detailed solution of what you did to fix this?Wack

© 2022 - 2024 — McMap. All rights reserved.