Error: Handshake inactivity timeout in Node.js MYSQL module

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

this._timeout  = 100000;

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.


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>