Error: Handshake inactivity timeout in Node.js MYSQL module

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.

I tried to change maually, and didn't work. I tried to change the sequence file to: this._idleTimeout = -1; and didn't help.

I read the issues and GitHub, and nothing helped.

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 }  

Answer #1:

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

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)

this._timeout  = 100000;
Answered By: Nick Kotenberg

Answer #2:

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.

The inbound rule should look as follows:

Type: MySQL/Aurora
Protocol: TCP (default)
Port: 3306 (default)
Source: <security group of instance>
Description: <optional>
Answered By: mscheker

Answer #3:

If you are using Amazon's services, I was able to resolve this by changing the allowed IP Addresses in the security settings or by changing the open connections ports.

Answered By: Berkay Torun

Answer #4:

.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.

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:

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());

Answer #5:

for those deploying on aws and heroku! enter in rds db instance settigns and change the inboud rule --> source: any..

Heroku dont provide a ip specific, remember!

Answered By: Edgar Olivar

Answer #6:

for me it was to correct the 'select' statment to select where checking the ID column (the primary key) and not column that it's type varchar , for example : not work

select from users where userName = 'aa';

work

select from users where userID = 1;
Answered By: Feiga Lubow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .



# More Articles