错误:mysql节点中出现致命错误后无法排队查询 [英] Error: Cannot enqueue Query after fatal error in mysql node

查看:91
本文介绍了错误:mysql节点中出现致命错误后无法排队查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用felixge/node-mysql.另外我正在使用express-myconnection,它可以防止mysql超时,进而防止杀死节点服务器.我正在做的是在mysql中记录活动.场景是我具有文件上传功能,一旦上传文件,我就对该文件执行不同的操作.在处理的每个阶段,我都将这些活动记录在数据库中.如果文件很小,这可以正常工作.如果文件很大(例如100 MB),则加载会花费一些时间,因此,与此同时,mysql服务器将重新连接并创建新连接,但日志记录代码仍使用旧引用.错误:致命错误后无法使查询入队.因此,我的问题是,有没有一种方法可以使用新的连接引用而不是旧的连接引用.有一个单一功能,其中发生与文件有关的所有不同活动阶段.任何帮助是极大的赞赏.谢谢

I am using felixge/node-mysql. Also I am using express-myconnection which prevents mysql timeout and in turn prevents killing of node server. What I am doing is logging the activities in mysql. The scenario is I have a file upload functionality once the file is uploaded I am performing different operations on the file. During every stage of processing I am logging those activities in database. This works fine if the file is small. If the file is large say 100 MB it takes some time to load so in the mean time the mysql server reconnects and creates a new connection but the logging code still uses the old reference. Error: Cannot enqueue Query after fatal error. So, my question is is there a way that i can use the new connection reference instead of the old one. There is a single function in which all the different phases of activities regarding file takes place. Any help is greatly appreciated. thanks

@paul,您好,如果您看到了要点链接,那么您可以看到我具有upload.on('begin',function(fileInfo,reqs,resp){},其中我记录了文件上传过程所具有的活动文件上传完成后,upload.on('end',函数(fileInfo,request,response){)被触发.我也在此处记录了一些活动.正如我在问题中说的,如果文件很大,则上传需要时间,同时创建一个新的MySql连接,但是'end'事件中的插入查询仍然引用旧的myconnection.所以,我想知道在这种情况下如何使用新的mysql连接引用?这更好地解释了这种情况.

Hi @paul, if you have seen the gist link you can see that I have the upload.on('begin', function (fileInfo, reqs, resp) { } where I have logged the activity that file upload process has begin. Once the file is uploaded upload.on('end', function (fileInfo,request,response) { } is triggered. I am also logging some activity here. As I said in my question, if the file is big the upload takes time. In the mean time a new MySql connection is created but the insert query in 'end' event still refers to the old myconnection. So, I wanted to know how can I use the new mysql connection reference in this scenario? I hope this has explained the scenario better.

推荐答案

实际上,我决定为您使用Google搜索您的错误,并在阅读此线程后:

Actually, I decided to google your error for you, and after reading this thread: https://github.com/felixge/node-mysql/issues/832 I realized that you're not releasing the connection after the first query completes, and so the pool never tries to issue you a new one. You were correct that the stale connection might be the problem. here's how you fix that if it is:

upload.on('begin', function (fileInfo, reqs, resp) { 
    var fileType = resp.req.fields.file_type;
    var originalFileName = fileInfo.name;
     var renamedFilename = file.fileRename(fileInfo,fileType);
    /*renaming the file */
    fileInfo.name = renamedFilename;

    /*start: log the details in database;*/
    var utcMoment = conf.moment.utc();
    var UtcSCPDateTime = new Date( utcMoment.format() );
    var activityData = {
        activity_type     : conf.LIST_UPLOAD_BEGIN,
        username          : test ,
        message           : 'test has started the upload process for the file',
        activity_datetime : UtcSCPDateTime 
    };
    reqs.params.activityData = activityData;
    req.getConnection(function(err,connection) {
    var dbData = req.params.activityData;
    var activity_type = dbData.activity_type;
    console.dir("[ Connection ID:- ] "+connection.threadId+' ] [ Activity type:- ] '+activity_type);
    var insertQuery = connection.query("INSERT INTO tblListmanagerActivityLog SET ? ",dbData, function(err, result) {
        if (err) {
            console.log("Error inserting while performing insert for activity "+activity_type+" : %s ",err );
        } else {
            console.log('Insert successfull');
        }
        /// Here is the change:
        connection.release();
    });

});
    /*end: log the details in database;*/
});

这篇关于错误:mysql节点中出现致命错误后无法排队查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆