首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >致命错误后的节点JS Mysql协议编码

致命错误后的节点JS Mysql协议编码
EN

Stack Overflow用户
提问于 2015-07-22 04:40:24
回答 2查看 28.7K关注 0票数 17

这个错误是什么意思?

{ [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 }

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-10-14 11:19:28

我认为问题出在express-sql-session上。我现在也遇到了同样的问题。我认为有人在这篇文章中发现了什么:NodeJS running on MAC, and have an error occurred when deploying on centOS

也来看看这个:https://github.com/felixge/node-mysql/issues/1166

票数 1
EN

Stack Overflow用户

发布于 2018-09-07 07:33:33

我在连接MySQL时也遇到过类似的问题。我使用连接池解决了这个问题。其概念是仅在需要时从连接池获取连接,并在使用后释放它。这样,连接就不会处于不稳定状态。您可以通过here获取实现详情。

票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31549193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档