这个错误是什么意思?
{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }
下面的代码可以在我的测试文件中运行:
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应用中使用这个函数时,我得到了错误:
{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }
为什么它能在我的测试中工作,而不能在我的应用程序中工作?
发布于 2015-10-14 11:19:28
我认为问题出在express-sql-session上。我现在也遇到了同样的问题。我认为有人在这篇文章中发现了什么:NodeJS running on MAC, and have an error occurred when deploying on centOS
发布于 2018-09-07 07:33:33
我在连接MySQL时也遇到过类似的问题。我使用连接池解决了这个问题。其概念是仅在需要时从连接池获取连接,并在使用后释放它。这样,连接就不会处于不稳定状态。您可以通过here获取实现详情。
https://stackoverflow.com/questions/31549193
复制相似问题