[Solved] Error: read ECONNRESET at TCP.onStreamRead Cannot enqueue Query after fatal error

Error analysis

This error often occurs when I use node to connect to MySQL. I wonder if it is because I do not close the connection every time I query the database after creating a MySQL connection, so the database is always connected and does not respond for a long time, resulting in the following error
error1:

error2:

 

Solution:

error1:

const mysql = require('mysql');
const connInfo = require('./config');

function queryMysql(sql, callback){
    const conn = mysql.createConnection(connInfo)
    conn.query(sql, (err, result)=>{
        if(err){
            console.log(err);
        }else {
            callback(result)
        }
        conn.end(err => {
            if(err){
                console.log(err)
            }
        })
    })
}

module.exports = queryMysql;

Error2:
We only need to configure useConnectionPooling true when instantiating SessionStore for example:

var sessionStore = new SessionStore({
    host: 'localhost' ,
    port: 3306 ,
    user: 'root' ,
    password: 'root' ,
    database: 'session' ,
    useConnectionPooling: true 
});

Read More: