当我使用node mysql时,在12:00至2:00之间会出现一个错误,即TCP连接被服务器关闭。以下是完整的错误信息:
Error: Connection lost: The server closed the connection.
at Protocol.end (/opt/node-v0.10.20-linux-x64/IM/node_modules/mysql/lib/protocol/Protocol.js:73:13)
at Socket.onend (stream.js:79:10)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
这里有一个解决方案。然而,我按照这种方式尝试后,问题仍然存在。现在我不知道该怎么办了。是否有人遇到过这个问题?
以下是我按照这个解决方案编写的方式:
var handleKFDisconnect = function() {
kfdb.on('error', function(err) {
if (!err.fatal) {
return;
}
if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
console.log("PROTOCOL_CONNECTION_LOST");
throw err;
}
log.error("The database is error:" + err.stack);
kfdb = mysql.createConnection(kf_config);
console.log("kfid");
console.log(kfdb);
handleKFDisconnect();
});
};
handleKFDisconnect();
if (err.code !== 'PROTOCOL_CONNECTION_LOST') { console.log("PROTOCOL_CONNECTION_LOST"); throw err; }
。如果不是PROTOCOL_CONNECTION_LOST
,则执行if()
块,但消息却说它是该错误...可能非常令人困惑。 - Alexis Wilke