错误:Node.js MYSQL 模块中的握手不活动超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35553432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Handshake inactivity timeout in Node.js MYSQL module
提问by Aminadav Glickshtein
I'm using node-mysql
and most of the queries. Working. some queries not working.
I tried every version of Node (from 0.5...) until (5.6.0), I also tried (4.0) and (4.1), Nothing helps.
我正在使用node-mysql
和大多数查询。在职的。一些查询不起作用。我尝试了每个版本的 Node(从 0.5...)直到(5.6.0),我也尝试过(4.0)和(4.1),没有任何帮助。
I tried to change maually, and didn't work. I tried to change the sequence
file to: this._idleTimeout = -1;
and didn't help.
我试图改变 maually,但没有奏效。我试图将sequence
文件更改为:this._idleTimeout = -1;
但没有帮助。
I read the issues and GitHub, and nothing helped.
我阅读了问题和 GitHub,但没有任何帮助。
I can try to fix it by myself, but I need more information. Where is the timeout, why? when? what is this type of message? Where is the timeout came from?
我可以尝试自己修复它,但我需要更多信息。超时在哪里,为什么?什么时候?这是什么类型的消息?超时从何而来?
MYSQL_ERROR { [Error: Handshake inactivity timeout]
code: 'PROTOCOL_SEQUENCE_TIMEOUT', fatal: true,
timeout: 10000 }
回答by Nick Kotenberg
Ok, the timeout comes from the Protocol.js file line:162. If you checkout node-mysql you'll see that it is a variable "timeout" for queries. If you set the timeout to something a lot higher than 10000, the default, then the error should go away. An example is
好的,超时来自 Protocol.js 文件 line:162。如果您签出 node-mysql,您会看到它是查询的变量“超时”。如果您将超时设置为远高于 10000(默认值),那么错误应该会消失。一个例子是
pool = require('mysql').createPool({
connectionLimit : 1000,
connectTimeout : 60 * 60 * 1000,
acquireTimeout : 60 * 60 * 1000,
timeout : 60 * 60 * 1000,
host : process.env.DB_HOST,
user : process.env.DB_USERNAME,
password : process.env.DB_PASSWORD,
database : process.env.DB_DATABASE
});
You can also edit the timeout in the Sequence.js file (node_modules/mysql/lib/protocol/sequence/Sequence.js)
您还可以在 Sequence.js 文件(node_modules/mysql/lib/protocol/sequence/Sequence.js)中编辑超时
this._timeout = 100000;
回答by mscheker
For those deploying on AWS
and experiencing this error, you'll need to make a change to the security group of your database/cluster and add an inbound rule
where the source
is the security group of your instance/s.
对于那些在部署AWS
和体验这个错误,你需要做出改变,以安全组数据库/集群,并add an inbound rule
在source
为您的实例的安全组/秒。
The inbound rule should look as follows:
入站规则应如下所示:
Type: MySQL/Aurora
Protocol: TCP (default)
Port: 3306 (default)
Source: <security group of instance>
Description: <optional>
回答by Berkay Torun
If you are using Amazon's services, I was able to resolve this by changing the allowed IP Addresses in the security settings orby changing the open connections ports.
如果您使用的是亚马逊的服务,我可以通过更改安全设置中允许的 IP 地址或更改开放连接端口来解决此问题。
回答by Edgar Olivar
for those deploying on aws and heroku! enter in rds db instance settigns and change the inboud rule --> source: any..
对于那些部署在 aws 和 heroku 上的人!输入 rds db instance settigns 并更改入站规则 --> 源:任何..
Heroku dont provide a ip specific, remember!
Heroku 不提供特定的 ip,记住!
回答by Elminson De Oleo Baez
.end() is non-blocking, but this may lead your code to the same issue that was in mine - I was just calling .end() w/o waiting the operation to actually complete.
.end() 是非阻塞的,但这可能会导致您的代码遇到与我相同的问题 - 我只是在调用 .end() 而不等待操作实际完成。
To actually wait for the connection end you can't just await dbConn.end(), because .end() doesn't return a promise. What you need is to create a promise and return it. Like the following:
要真正等待连接结束,您不能只等待 dbConn.end(),因为 .end() 不会返回承诺。您需要的是创建一个承诺并返回它。像下面这样:
From
从
connection.end();
To this
对此
connection.end(error => error ? reject(error) : resolve());
And for pool using
对于池使用
connection.release();
To this
对此
connection.release(error => error ? reject(error) : resolve());