Share On Twitter Facebook Google+ LinkedIn Pinterest Tumblr Reddit
Question

(node:868) UnhandledPromiseRejectionWarning: Error: Handshake inactivity timeout

Tags: node.js error Handshake
Date:
Status:Resolved
Question Id:31

I have a problem on node.js with mysql. When I inserted a record, node.js gave me this error:

(node:868) UnhandledPromiseRejectionWarning: Error: Handshake inactivity timeout

But other queries works without problems. I think the problem can be query. Please help me

INSERT INTO forms
    (pro_no, creation_date, clinic, result)
      VALUES('${f.pro_no}', '${creation_date}', '${f.clinic}','${f.result}');`);
Answer
Date:
Correct:No

I think it is not about your query. Change connection parameters:

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;
Answer
Date:
Correct:No

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.

Answer
Date:
Correct:Yes

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:

 

TypeMySQL/Aurora
ProtocolTCP (default)
Port3306 (default)
Source<security group of instance>
Description: <optional></optional>
Answer
Date:
Correct:No

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

Your Answer

Review Your Answer