致命错误后节点JS Mysql协议排队 [英] Node JS Mysql PROTOCOL ENQUEUE AFTER FATAL ERROR
本文介绍了致命错误后节点JS Mysql协议排队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误是什么意思?
{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }
此代码可在我的测试文件中使用:
This code works in my test file:
function handleDisconnect() {
objConn = mysql.createConnection(db_config); // Recreate the connection, since
// the old one cannot be reused.
objConn.connect(function(err) { // The server is either down
if(err) { // or restarting (takes a while sometimes).
console.log('error when connecting to db:', err.code);
setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
}else{
console.log('Connected to db!');
} // to avoid a hot loop, and to allow our node script to
}); // process asynchronous requests in the meantime.
// If you're also serving http, display a 503 error.
objConn.on('error', function(err) {
if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
handleDisconnect(); // lost due to either server restart, or a
}else{
throw err;
}
});
}
handleDisconnect();
megaLoop();
function megaLoop(){
objConn.query('SELECT u.`email` FROM `users` as u', function(err, rows) {
console.log(err);
console.log(rows);
});
setTimeout(megaLoop, 100);
}
但是当我在Express App中使用该功能时,会出现错误:
But when I use the function in my Express App I get the error:
{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }
为什么它在我的测试中而不在我的应用程序中起作用?
Why does it work in my test and not my app?
推荐答案
我认为问题是express-sql-session.我现在遇到同样的问题.我认为有人正在处理此帖子:
I believe the issue is an express-sql-session. I'm experiencing the same issue right now. I think someone is on to something at this post: NodeJS running on MAC, and have an error occurred when deploying on centOS
也请检查以下内容: https://github.com/felixge/node- mysql/issues/1166
这篇关于致命错误后节点JS Mysql协议排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文