Resolving handshake inactivity timeout error in Node.js's MYSQL module
P粉205475538
P粉205475538 2023-08-22 16:34:16
0
2
541
<p>I'm using <code>node-mysql</code> and most of the queries work fine. But some queries don't work. I tried every version of Node (from 0.5... to 5.6.0), I also tried 4.0 and 4.1 but neither helped. </p> <p>I tried changing it manually but it didn't work. I tried changing the <code>sequence</code> file to: <code>this._idleTimeout = -1;</code> but that didn't help either. </p> <p>I read the issue and the stuff on GitHub but it didn't help. </p> <p>I could try to fix it myself, but I need more information. Where does the timeout occur? Why? When did it happen? What type of message is this? Where does the timeout come from? </p> <pre class="brush:php;toolbar:false;">MYSQL_ERROR { [Error: Handshake inactivity timeout] code: 'PROTOCOL_SEQUENCE_TIMEOUT', fatal: true, timeout: 10000 }</pre> <p><br /></p>
P粉205475538
P粉205475538

reply all(2)
P粉547420474

For those deploying on AWS and encountering this error, you will need to make changes to the security group of the database/cluster, Add an inbound rule where source is the security group of the instance.

The inbound rules should look like this:

类型:MySQL/Aurora
协议:TCP(默认)
端口:3306(默认)
源:<实例的安全组>
描述:<可选>
P粉155128211

Okay, the timeout is from line 162 of the Protocol.js file. If you look at node-mysql, you will see that the variable queried is "timeout". If you set the timeout to a much higher value than the default of 10000, the error should go away. An example is

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/sequences/Sequence.js)

this._timeout  = 100000;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template