【发布时间】:2013-12-11 05:01:10
【问题描述】:
当我使用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)
有solution。但是,我通过这种方式尝试后,问题也出现了。现在我不知道该怎么办。有人遇到这个问题吗?
下面是我写的方法:
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; }。如果if()不是 notPROTOCOL_CONNECTION_LOST,则您执行该块,但消息说这是错误...可能非常令人困惑。
标签: mysql node.js dbconnection