与mysql的节点服务器连接丢失

flvlnr44  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(285)

与aws-rds的连接经常丢失,不会发出任何错误事件,如 PROTOCOL_CONNECTION_LOST 在使用池连接时。当api服务器收到请求时,mysql返回空数组而不是error。
我可以在rds Jmeter 板中看到连接断开,但没有发出错误事件。我试过一些解决办法,比如改变 mysql_connections_options 就像 connectTimeout , wait_timeout 等等,另外,我也尝试过在短时间内定期ping mysql服务器(返回正确的结果),但仍然会丢失连接,查询返回空数组作为结果,没有任何错误。
这是我的连接代码:

connection = mysql.createPool(mysqlConnectionOptions);
function pingSqlServerForPersistentConnection() {
    console.log("PINGING : ");
    connection.getConnection(function (err) {
        if (err) {
            console.log('MYSQL ERROR CONNECTION : ' + err);

            pingSqlServerForPersistentConnection();
        }
        else {
            if (config.get("APP_NAME") == "prod") {
                setInterval(selectStar, 150000);
            }
            console.log('Connection established');
        }
    });
    connection.on('error', function (err) {
        console.log("MYSQL DISCONNECTED : ", JSON.stringify(err));
        pingSqlServerForPersistentConnection();
        if (err.code === 'PROTOCOL_CONNECTION_LOST') {
            console.log("MYSQL : \n PROTOCOL_CONNECTION_LOST");
            pingSqlServerForPersistentConnection();
        }
        if (err.code === 'ETIMEDOUT') {
            console.log("MYSQL : ETIMEDOUT");
            pingSqlServerForPersistentConnection();
        }
    });
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题