发现线上系统几小时就会发生内存溢出,通过排查找到系统中大量SequelizeConnectionError异常信息。 { [SequelizeConnectionError: Cannot enqueue Quit after fatal error.] name: ‘SequelizeConnectionError’, message: ‘Cannot enqueue Quit after fatal error.’, parent: { [Error: Cannot enqueue Quit after fatal error.] code: ‘PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR’, fatal: false }, original: { [Error: Cannot enqueue Quit after fatal error.] code: ‘PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR’, fatal: false } } Promise { _bitField: 18087936, _fulfillmentHandler0: { [SequelizeConnectionError: Cannot enqueue Quit after fatal error.] name: ‘SequelizeConnectionError’, message: ‘Cannot enqueue Quit after fatal error.’, parent: { [Error: Cannot enqueue Quit after fatal error.] code: ‘PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR’, fatal: false }, original: { [Error: Cannot enqueue Quit after fatal error.] code: ‘PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR’, fatal: false } }, _rejectionHandler0: undefined, _promise0: undefined, _receiver0: undefined }
几乎是同一套系统部署在不同服务器上,其中一个服务出现上面sequelize异常。 请问大家这是是mysql连接池的问题吗,目前连接池最大连接是30,有没有哪位同事碰到过类似问题?
mysql 默认配置的 wait_timeout 导致的
function handleDisconnect() {
// Recreate the connection, since
// the old one cannot be reused.
connection = mysql.createConnection(dbConfig);
connection.connect(function(err) {
// The server is either down
// or restarting
if(err) {
// We introduce a delay before attempting to reconnect,
// to avoid a hot loop, and to allow our node script to
// process asynchronous requests in the meantime.
console.log('error when connecting to db:', err);
setTimeout(handleDisconnect, 2000);
}
});
connection.on('error', function(err) {
console.log('db error', err);
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
handleDisconnect();
}else{
throw err;
}
});
}