PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR nodejs mysql

时间:2019-05-12 07:25:45

标签: javascript mysql node.js node-mysql

如果我离开软件超过2到4个小时,我每天都会遇到错误。

{
    code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', 
    fatal: false 
}

{ Error: Cannot enqueue Handshake after fatal error.
    at Protocol._validateEnqueue (/home/zubizi/retech_node_beta/node_modules/mysql/lib/protocol/Protocol.js:200:16)
    at Protocol._enqueue (/home/zubizi/retech_node_beta/node_modules/mysql/lib/protocol/Protocol.js:138:13)
    at Protocol.handshake (/home/zubizi/retech_node_beta/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/home/zubizi/retech_node_beta/node_modules/mysql/lib/Connection.js:118:18)
    at connectMysql (/home/zubizi/retech_node_beta/index.js:38:14)
    at Connection.<anonymous> (/home/zubizi/retech_node_beta/index.js:52:13)
    at Connection.emit (events.js:182:13)
    at Connection._handleProtocolError (/home/zubizi/retech_node_beta/node_modules/mysql/lib/Connection.js:425:8)
    at Protocol.emit (events.js:182:13)
    at Protocol._delegateError (/home/zubizi/retech_node_beta/node_modules/mysql/lib/protocol/Protocol.js:390:10)
    at Protocol.end (/home/zubizi/retech_node_beta/node_modules/mysql/lib/protocol/Protocol.js:116:8)
    at Socket.<anonymous> (/home/zubizi/retech_node_beta/node_modules/mysql/lib/Connection.js:97:28)
    at Socket.<anonymous> (/home/zubizi/retech_node_beta/node_modules/mysql/lib/Connection.js:502:10)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1094:12)
    at args.(anonymous function) (/home/zubizi/.nvm/versions/node/v11.2.0/lib/node_modules/pm2/node_modules/event-loop-inspector/index.js:138:29)
    at process.internalTickCallback (internal/process/next_tick.js:72:19) code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR', fatal: false }

我尝试了以下代码来保持连接状态。但是结果还是一样。

// keep connection alive 
setInterval(function () {
    var datetime = moment.format('DD-MM-YYYY');
    conn.query('SELECT 1');
    console.log('Keep alive the connection. ' + datetime);
}, 10000);

我使用这种方法与MySQL连接

const conn = mysql.createConnection(config);


conn.connect(function (err) {
    if (err) {
        console.error(err);
        // process.exit(1);
    } else {
        console.log(`DB Host: ${config.host}, DB: ${config.database}`);
        console.log("Connected!");
    }
});

,如果有任何用户登录,我将像这样更改数据库:

conn.changeUser({
    database: req.session.dbname
}, function (err) {
    if (err) {
        console.log(err);
    } else {
        next();
    }
});

过程是否错误或对此有解决方案?

0 个答案:

没有答案