nodejs mysql handleDisconnect get" ECONNREFUSED"它不一致地发生

时间:2018-06-17 11:58:50

标签: mysql node.js

什么时候启动服务器,我向节点发出一些请求,节点正确地从MySQL获取数据,节点和MySQL服务器之间的连接似乎很好,但过了一段时间,我得到下一个错误原因?

这是代码:

function handleDisconnect() {
connection = mysql.createConnection(config.get('MySql'));
connection.connect(function (err) {           
    if (err) {                                   
        console.log(dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss:l"), get 
           data reconnecting to db:', err);
        setTimeout(handleDisconnect, 2000); 
    } else {
        console.log(dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss:l"), 
           "INFO", "Database in get data module is connected ... nn");
    }                                     
});                                     

connection.on('error', function (err) {
    console.log('lost db connection in report modules reconnecting');
    if (err.code === 'PROTOCOL_CONNECTION_LOST') { 
        handleDisconnect();                       
    } else {                                      
        throw err;                                 
    }
});

handleDisconnect();

这是我得到的错误:

2018-06-16 22:19:23:985 ERRORE lost connection in get data reconnecting 
to db: { Error: connect ECONNREFUSED *.*.*.*:3306
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
--------------------
at Protocol._enqueue
  (/home/bla/workspace/bla/Server/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake 

 (/home/bla/workspace/bla/Server/node_modules/mysql/lib/protocol/Protocol.js :52:23)
 at Connection.connect 
         (/home/bla/workspace/bla/Server/node_modules/mysql/lib/Connection.js:130:18)
at Timeout.handleDisconnect [as _onTimeout]     (/home/bla/workspace/bla/Server/routes/getData.js:11:16)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)


errno: 'ECONNREFUSED',
syscall: 'connect',
address: '*.*.*.*',
port: 3306,
fatal: true 
}

0 个答案:

没有答案