有什么问题吗?
server disconnects / wait_timeouts,就像这里提到的:https://github.com/felixge/node-mysql#server-disconnectsThis socket has been ended by the other party错误消息。我想做的是
// Connect Function
db.connect = function(callback){
// Destory the Connection if there is already one
if(db.connection) {
console.log('[mysql]','connection destroy');
db.connection.destroy();
db.connection = null;
}
// Create the Connection
db.connection = MySQL.createConnection(options);
// Connect using the Connection
db.connection.connect(function(error) {
if(error){
console.log('[mysql]', 'connect failed', error);
} else {
console.log('[mysql]', 'connection success');
db.connection.database = options.database;
callback(db.connection, error);
}
});
// Listen on Connection Errors
db.connection.on('error', function(error) {
// Connection to the MySQL server is usually
// lost due to either server restart, or a
// connnection idle timeout (the wait_timeout server variable configures this)
if(error.code === 'PROTOCOL_CONNECTION_LOST') {
console.log('[mysql]', 'PROTOCOL_CONNECTION_LOST')
db.connect(callback);
} else {
console.log('[mysql] Connection Error: ', error);
}
});
// Return Connection Instance
return db.connection;
}更多细节
wait_timeout和interactive_timeout必须在my.cnf中设置约10秒才能测试该问题。
[mysqld]
wait_timeout = 10
interactive_timeout = 10发布于 2014-08-11 11:12:50
库意外地试图在接收到FIN数据包后对TCP套接字进行写入,这意味着TCP连接被另一方关闭了一半。我将修复这个错误信息,以给您一个更好的错误消息,但它仍然是一个错误;要么您的网络正在扼杀您的MySQL连接或其他什么。
你在使用连接池吗?看起来,根据堆栈跟踪,在超时之后,您只是在对连接进行查询。这可能是您保持一个不活动的连接时间太长,网络或MySQL服务器上的某些东西正在结束连接。
https://stackoverflow.com/questions/23333295
复制相似问题