小编典典

致命错误后节点JS Mysql协议排队

mysql

错误是什么意思?

{ [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 App中使用该功能时,出现错误:

{ [Error: Cannot enqueue Query after fatal error.] code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }

为什么它在我的测试中而不在我的应用程序中起作用?


阅读 431

收藏
2020-05-17

共1个答案

小编典典

我相信问题是Express-sql-
session。我现在遇到同样的问题。我认为有人正在处理以下内容:NodeJS在MAC上运行,并且在centOS上部署时发生错误

也检查一下:https :
//github.com/felixge/node-mysql/issues/1166

2020-05-17