未处理拒绝错误:握手不活动超时。 我运行app并在连接到db期间获取错误,以便获取数据。我删除了node_modules文件夹。通过nvm将节点版本从4.4.7更改为6.10.0。再次安装node_modules。试图扩大连接选项的超时。试图使用没有promisify所有的mysql2。什么都没有帮助。 我读到了有关路由器的DNS地址的混淆(但是连接正在与节点4.4.7一起使用)。我也明白同样的问题在以前的版本中,但我没有找到强大且可理解的答案,只有关于路由,CPU,错误的配置连接的建议。
OS: Centos 7
node //Now using node v6.10.0 (npm v3.10.10) via nvm
mysql module: 2.13.0
mysql db : //some DNS name (not local), port : 3306
CODE (LIB / MySQL的/ index.js)
var Promise = require("bluebird");
// The most popular mysql module
var mysql = require('mysql');
// Note that the library's classes are not properties of the main export
// so we require and promisifyAll them manually
Promise.promisifyAll(require("mysql/lib/Connection").prototype);
Promise.promisifyAll(require("mysql/lib/Pool").prototype);
var config = require(__base + '/config');
var connections = {};
Object.keys(config.mysql).forEach(function (name) {
var options = config.mysql[name];
new Connection(name, options || null);
});
/**
* @param name
* @param options
* host : options.host,
* port : options.port,
* user : options.user,
* password: options.password,
* database: options.database
*
* @constructor
*/
function Connection(name, options) {
this.name = name;
var connectionObj = options;
connectionObj.connectionLimit = 10;
this.pool = mysql.createPool(connectionObj);
this.runQuery = function (query) {
return this.pool.queryAsync(query);
};
connections[name] = this;
}
function setConnection(name , options ){
connections[name] = new Connection(name,options)
}
function getConnection( name, options ){
if( !connections[name]){
setConnection(name,options);
}
return connections[name];
}
exports.connections = connections;
exports.getConnection = getConnection;
Unhandled rejection Error: Handshake inactivity timeout
at Handshake.<anonymous>
(/home/User/code/application/node_modules/mysql/lib/protocol/Protocol.js:160:17)
at emitNone (events.js:86:13)
at Handshake.emit (events.js:185:7)
at Handshake._onTimeout (/home/User/code/application/node_modules/mysql/lib/protocol/sequences/Sequence.js:127:8)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
--------------------
at Protocol._enqueue (/home/User/code/application/node_modules/mysql/lib/protocol/Protocol.js:141:48)
at Protocol.handshake (/home/User/code/application/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at PoolConnection.connect (/home/User/code/application/node_modules/mysql/lib/Connection.js:130:18)
at Pool.getConnection (/home/User/code/application/node_modules/mysql/lib/Pool.js:48:16)
at Pool.query (/home/User/code/application/node_modules/mysql/lib/Pool.js:202:8)
at Pool.tryCatcher (/home/User/code/application/node_modules/bluebird/js/release/util.js:16:23)
at Pool.ret [as queryAsync] (eval at makeNodePromisifiedEval (/home/User/code/application/node_modules/bluebird/js/release/promisify.js:205:1), <anonymous>:14:23)
at Connection.__dirname.Connection.options.runQuery (/home/User/code/application/lib/mysql/index.js:50:26)
at TableName.runQuery (/home/User/code/application/models/mysql/abstract.js:51:34)
at TableName.proto.getAll (/home/User/code/application/models/mysql/abstract.js:60:17)
at new TableName (/home/User/code/application/models/mysql/table_name.js:11:33)
at Object.<anonymous> (/home/User/code/application/models/mysql/table_name.js:58:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
我试着像这里一样放大超时:Error: Handshake inactivity timeout in Node.js MYSQL module。
我在这里阅读了有关DNS设置的信息:Error: Handshake inactivity timeout in Node.js v6.9.1 and MYSQL。 (对于节点4.4.7,没有问题)。
答案 0 :(得分:0)
App在调试模式下在IDE WebStorm v.11中运行并失败。 我将IDE更新到更新版本2016.3。问题消失了。