Error: Cannot enqueue Query after fatal error in mysql node

前端 未结 3 1065
离开以前
离开以前 2021-01-15 16:45

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

3条回答
  •  旧时难觅i
    2021-01-15 16:57

    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;*/
    });
    

提交回复
热议问题