gpt4 book ai didi

mysql - 握手不活动超时 : nodejs 6. 10.0 mysql pool.queryAsync

转载 作者:行者123 更新时间:2023-11-30 22:03:00 25 4
gpt4 key购买 nike

未处理的拒绝错误:握手不活动超时。我运行应用程序并在连接到数据库期间收到错误以防获取数据。我删除了 node_modules 文件夹。通过 nvm 将 Node 版本从 4.4.7 更改为 6.10.0。再次安装 node_modules。试图扩大连接选项的超时时间。试图在不 promise 所有的情况下使用 mysql2。没有任何帮助。我读到了 DNS 地址与路由器的冲突(但是连接正在与 Node 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

代码(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 . (对于 Node 4.4.7 没有问题)。

最佳答案

应用程序在 IDE WebStorm v.11 中以 Debug模式运行并失败。我将 IDE 更新到更新版本 2016.3。问题消失了。

关于mysql - 握手不活动超时 : nodejs 6. 10.0 mysql pool.queryAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42767357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com